Cocos2d iphone 无法添加精灵帧并在CCSprite中使用
我正在使用以下代码加载纹理图集:Cocos2d iphone 无法添加精灵帧并在CCSprite中使用,cocos2d-iphone,Cocos2d Iphone,我正在使用以下代码加载纹理图集: [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"zones.plist"]; CGSize screenSize = [CCDirector sharedDirector].viewSize; sprite = [CCSprite spriteWithImageNamed:@"Z_11.png"]; sprite.position = ccp(
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"zones.plist"];
CGSize screenSize = [CCDirector sharedDirector].viewSize;
sprite = [CCSprite spriteWithImageNamed:@"Z_11.png"];
sprite.position = ccp(screenSize.width * 0.5, screenSize.height * 0.5);
[self addChild:sprite];
但没有添加任何内容。
我还尝试:
CCSpriteFrame *sf = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"ZONE_2"];
sprite = [CCSprite spriteWithSpriteFrame:sf];
我得到一个错误:
'Invalid spriteFrame for sprite'
我做错了什么吗?如果zones.plist包含帧的定义,它很可能是
ZONE_2.png
(假设它是由诸如TexturePacker之类的工具生成的)。尝试:
编辑:
另外,请确保您为计划支持的所有设备/显示模式配备了适当的资源(如zones-hd.plist等)。显示zones-hd.plist的内容(如果您支持hd)。
CCSpriteFrame *sf = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"ZONE_2.png"];