cocos2d-x精灵更换图片

前端之家收集整理的这篇文章主要介绍了cocos2d-x精灵更换图片前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

通过更换纹理/精灵帧实现

例子1

<pre name="code" class="cpp">local sprite1 = cc.Sprite:create( "dog.png" )

local sprite2 = cc.Sprite:create( "cat.png" )

sprite1:setTexture( sprite2:getTexture() )

sprite1:setTextureRect( sprite2:getTextureRect() )
 

例子2

<pre name="code" class="cpp">cc.SpriteFrameCache:getInstance():addSpriteFrames( "animals.plist" )

local sprite1 = cc.Sprite:create( "dog.png" )

local sprite2 = cc.Sprite:create( "cat.png" )

sprite1:setTexture( sprite2:getTexture() )

sprite1:setTextureRect( sprite2:getTextureRect() )
 
 

例子3

<pre name="code" class="cpp">cc.SpriteFrameCache:getInstance():addSpriteFrames( "animals.plist" )

local sprite1 = cc.Sprite:create( "dog.png" )

local sprite2 = cc.Sprite:create( "cat.png" )

sprite1:setSpriteFrame( sprite2:getSpriteFrame() )
原文链接:https://www.f2er.com/cocos2dx/345963.html

猜你在找的Cocos2d-x相关文章