How to convert a CCSpriteFrame to a CCTexture2D (Cocos2d)

后端 未结 2 1269
野趣味
野趣味 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];
    
    0 讨论(0)
  • 2021-01-26 16:59

    Yes, it has a texture function:

    [[[CCSpriteFrameCache sharedSpriteFrameCache]spriteFrameByName:@"MyFrame"]texture];
    

    CCSprites have a method called setTexture or something.

    0 讨论(0)
提交回复
热议问题