Ben*_*ani 6 texture2d cocos2d-iphone ccsprite
我有一个使用初始化的CCSprite [CCSprite spriteWithSpriteFrameName:@"plist_file_key_here.png"].我已经将plist文件中的所有sprite添加到CCSpriteFrameCache中.我试过像这样设置纹理:
CCSpriteFrame * frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:name];
NSAssert(frame.texture!=nil, @"frame.texture can't equal nil"); //this works fine
[sprite setTexture:frame.texture]; //doesn't cause a white square to appear, just doesn't switch the image.
Run Code Online (Sandbox Code Playgroud)
正如我在评论中所说,这不起作用.我认为它与using [CCSprite spriteWithFile:]和之间的区别有关[CCSprite spriteWithSpriteFrameName:],它依赖于从纹理图集加载到CCSpriteFrameCache中的精灵帧.当使用从纹理图集加载的精灵时,每个精灵的纹理等于精灵图纸的纹理.有没有办法解决这个问题,还是我必须删除并重新创建精灵?如果这是我唯一的选择,有没有办法从其父节点删除ccnode但保留其子节点?
Lea*_*s2D 17
当你有一个带有精灵框架的纹理时,你不想改变纹理但是精灵使用的精灵框架.你可以这样做:
CCSpriteFrameCache* cache = [CCSpriteFrameCache sharedSpriteFrameCache];
CCSpriteFrame* frame = [cache spriteFrameByName:name];
sprite.displayFrame = frame;
Run Code Online (Sandbox Code Playgroud)
在cocos2d v3中,它需要是:
sprite.spriteFrame = frame;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10624 次 |
| 最近记录: |