本文介绍了如何将CCSpriteFrame转换为CCTexture2D(Cocos2d)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可以转换从 CCSpriteFrameCache
中获取的 CCSpriteFrame
,并将其转换为可以设置在sprite纹理属性上?
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 property?
推荐答案
假设你的CCSpriteFrame命名为 frame
您可以使用:
Assuming your CCSpriteFrame is named frame
you can use:
[sprite setDisplayFrame:frame];
到。如果纹理不一样,你必须创建一个新的sprite:
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];
但是由于你已经有了CCSpriteFrame,你可以调用:
But since you already have the CCSpriteFrame you can just as well call initWithFrame:
CCSprite* sprite = [CCSprite spriteWithSpriteFrame:frame];
这篇关于如何将CCSpriteFrame转换为CCTexture2D(Cocos2d)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!