我正在使用Cocos2D 2.0开发iPad。
我有以下几行:
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"atlas.plist"];
CCSpriteBatchNode *batchNode = [CCSpriteBatchNode batchNodeWithFile:@"atlas.png"];
[self addChild:batchNode];
CCSprite *mySprite = [CCSprite spriteWithFrameName:@"white.png"];
它因这个错误而惨遭失败:
Cocos2d:CCSpriteFrameCache:找不到框架'white.png' * 断言失败 - [CCSprite initWithSpriteFrame:],/ Users / myUser / Files / MyApp / MyApp / libs / circos2d / CCSprite.m:212 **
我使用TexturePacker生成了plist。 TexturePacker创建了4个文件:atlas-ipadhd.plis,atlas-ipadhd.png,atlas.plist和atlas.png。
white-ipadhd.png是2x2白色图片。 white.png是1x1白色图片。
这是atlas-ipadhd的内容
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>frames</key>
<dict>
<key>white-ipadhd.png</key>
<dict>
<key>frame</key>
<string>{{162,2},{2,2}}</string>
<key>offset</key>
<string>{0,0}</string>
<key>rotated</key>
<false/>
<key>sourceColorRect</key>
<string>{{0,0},{2,2}}</string>
<key>sourceSize</key>
<string>{2,2}</string>
</dict>
<key>bgNormal-ipadhd.png</key>
<dict>
<key>frame</key>
<string>{{2,2},{348,78}}</string>
<key>offset</key>
<string>{0,0}</string>
<key>rotated</key>
<true/>
<key>sourceColorRect</key>
<string>{{0,0},{348,78}}</string>
<key>sourceSize</key>
<string>{348,78}</string>
</dict>
<key>bgPressed-ipadhd.png</key>
<dict>
<key>frame</key>
<string>{{82,2},{348,78}}</string>
<key>offset</key>
<string>{0,0}</string>
<key>rotated</key>
<true/>
<key>sourceColorRect</key>
<string>{{0,0},{348,78}}</string>
<key>sourceSize</key>
<string>{348,78}</string>
</dict>
</dict>
<key>metadata</key>
<dict>
<key>format</key>
<integer>2</integer>
<key>realTextureFileName</key>
<string>atlas-ipadhd.png</string>
<key>size</key>
<string>{256,512}</string>
<key>smartupdate</key>
<string>$TexturePacker:SmartUpdate:f709325b7d140d102cd10dd90ef475b0$</string>
<key>textureFileName</key>
<string>atlas-ipadhd.png</string>
</dict>
</dict>
</plist>
这是atlas.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>frames</key>
<dict>
<key>white.png</key>
<dict>
<key>frame</key>
<string>{{84,2},{1,1}}</string>
<key>offset</key>
<string>{0,0}</string>
<key>rotated</key>
<false/>
<key>sourceColorRect</key>
<string>{{0,0},{1,1}}</string>
<key>sourceSize</key>
<string>{1,1}</string>
</dict>
<key>bgNormal.png</key>
<dict>
<key>frame</key>
<string>{{2,2},{174,39}}</string>
<key>offset</key>
<string>{0,0}</string>
<key>rotated</key>
<true/>
<key>sourceColorRect</key>
<string>{{0,0},{174,39}}</string>
<key>sourceSize</key>
<string>{174,39}</string>
</dict>
<key>bgPressed.png</key>
<dict>
<key>frame</key>
<string>{{43,2},{174,39}}</string>
<key>offset</key>
<string>{0,0}</string>
<key>rotated</key>
<true/>
<key>sourceColorRect</key>
<string>{{0,0},{174,39}}</string>
<key>sourceSize</key>
<string>{174,39}</string>
</dict>
</dict>
<key>metadata</key>
<dict>
<key>format</key>
<integer>2</integer>
<key>realTextureFileName</key>
<string>atlas.png</string>
<key>size</key>
<string>{128,256}</string>
<key>smartupdate</key>
<string>$TexturePacker:SmartUpdate:c3c8dd4637d116b049a6b55c8ad175d0$</string>
<key>textureFileName</key>
<string>atlas.png</string>
</dict>
</dict>
</plist>
这是atlas-ipadhd.png和atlas.png
看了几个小时之后,我无法找到这些文件的任何问题......但它仍然会发生灾难性的灾难。
任何线索?感谢。
答案 0 :(得分:1)
精灵帧名称应为atlas-ipadhd.plist中的white.png。
直接从马的嘴里出来:+(id)spriteWithSpriteFrameName:(NSString*)spriteFrameName
{
CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:spriteFrameName];
NSAssert1(frame!=nil, @"Invalid spriteFrameName: %@", spriteFrameName);
return [self spriteWithSpriteFrame:frame];
}
没有尝试使用设备特定键更正帧名称。这样,您的代码可以保持完全与设备无关,您只需使用适当的设备特定文件名提供资源(纹理和plist)。