How to convert a CCSpriteFrame to a CCTexture2D (Cocos2d)

后端 未结 2 1272
野趣味
野趣味 2021-01-26 16:35

Is it possible to convert a CCSpriteFrame that was taken from CCSpriteFrameCache, and convert it into a texture that can be set on a sprite texture pro

2条回答
  •  不知归路
    2021-01-26 16:50

    Assuming your CCSpriteFrame is named frame you can use:

    [sprite setDisplayFrame:frame];
    

    to change the sprite's frame if it uses the same texture. If the texture is not the same, you must create a new sprite:

    CCSprite* sprite = [CCSprite spriteWithTexture:frame.texture];
    [sprite setDisplayFrame:frame];
    

    But since you already have the CCSpriteFrame you can just as well call initWithFrame:

    CCSprite* sprite = [CCSprite spriteWithSpriteFrame:frame];
    

提交回复
热议问题