Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocos2d iphone Cocos2d 2.0-找不到spriteFrame?_Cocos2d Iphone - Fatal编程技术网

Cocos2d iphone Cocos2d 2.0-找不到spriteFrame?

Cocos2d iphone Cocos2d 2.0-找不到spriteFrame?,cocos2d-iphone,Cocos2d Iphone,我正在用CoCoS2D2.0为iPad开发 我有以下几行: [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"atlas.plist"]; CCSpriteBatchNode *batchNode = [CCSpriteBatchNode batchNodeWithFile:@"atlas.png"]; [self addChild:batchNode]; CCSprite *mySprite = [C

我正在用CoCoS2D2.0为iPad开发

我有以下几行:

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"atlas.plist"];
CCSpriteBatchNode *batchNode = [CCSpriteBatchNode batchNodeWithFile:@"atlas.png"];
[self addChild:batchNode];

CCSprite *mySprite = [CCSprite spriteWithFrameName:@"white.png"];
它因以下错误而惨败:

Cocos2d:CCSpriteFrameCache:Frame'white.png'未找到 *在-[CCSprite initwithpriteframe:]、/Users/myUser/Documents/MyApp/MyApp/libs/cocos2d/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>

框架
白色-ipadhd.png
框架
{{162,2},{2,2}}
抵消
{0,0}
旋转
sourceColorRect
{{0,0},{2,2}}
源大小
{2,2}
bgmnormal-ipadhd.png
框架
{{2,2},{348,78}}
抵消
{0,0}
旋转
sourceColorRect
{{0,0},{348,78}}
源大小
{348,78}
bg-ipadhd.png
框架
{{82,2},{348,78}}
抵消
{0,0}
旋转
sourceColorRect
{{0,0},{348,78}}
源大小
{348,78}
元数据
格式
2.
realTextureFileName
atlas-ipadhd.png
大小
{256,512}
智能更新
$TexturePack:SmartUpdate:f709325b7d140d102cd10dd90ef475b0$
纹理名称
atlas-ipadhd.png
这是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>

框架
white.png
框架
{{84,2},{1,1}}
抵消
{0,0}
旋转
sourceColorRect
{{0,0},{1,1}}
源大小
{1,1}
bgmnormal.png
框架
{{2,2},{174,39}}
抵消
{0,0}
旋转
sourceColorRect
{{0,0},{174,39}}
源大小
{174,39}
bgp.png
框架
{{43,2},{174,39}}
抵消
{0,0}
旋转
sourceColorRect
{{0,0},{174,39}}
源大小
{174,39}
元数据
格式
2.
realTextureFileName
atlas.png
大小
{128,256}
智能更新
$TexturePack:SmartUpdate:c3c8dd4637d116b049a6b55c8ad175d0$
纹理名称
atlas.png
这是atlas-ipadhd.png和atlas.png

在看了几个小时后,我找不到这些文件有什么问题。。。但它仍然以灾难性的方式崩溃


有什么线索吗?谢谢。

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];
}

没有尝试使用设备特定键更正帧名称。通过这种方式,您的代码可以保持完全的设备无关性,您只需为资源(纹理和plists)提供适当的设备特定文件名。

为什么?每个plist不应该参考他们的对应文件吗?为什么ipadhd plist应该引用非hd文件?我想这是coco程序员的设计决定。coco为什么选择如此丑陋的xml模式?