我已经创建了一个在模拟器上工作正常的动画,但是当我使用我的设备时,屏幕上会出现一个大十字。我得到以下日志消息。
SKTexture: Error loading image resource: "Bird1"
我已经仔细检查过所有纹理都在捆绑资源中。怎么会在设备上显示出来?
SKTexture* birdTexture1 = [SKTexture textureWithImageNamed:@"Bird1"];
birdTexture1.filteringMode = SKTextureFilteringNearest;
SKTexture* birdTexture2 = [SKTexture textureWithImageNamed:@"Bird2"];
birdTexture2.filteringMode = SKTextureFilteringNearest;
SKTexture* birdTexture3 = [SKTexture textureWithImageNamed:@"Bird3"];
birdTexture3.filteringMode = SKTextureFilteringNearest;
SKTexture* birdTexture4 = [SKTexture textureWithImageNamed:@"Bird4"];
birdTexture4.filteringMode = SKTextureFilteringNearest;
SKTexture* birdTexture5 = [SKTexture textureWithImageNamed:@"Bird5"];
birdTexture5.filteringMode = SKTextureFilteringNearest;
SKTexture* birdTexture6 = [SKTexture textureWithImageNamed:@"Bird6"];
birdTexture6.filteringMode = SKTextureFilteringNearest;
SKAction *flap = [SKAction repeatActionForever:[SKAction animateWithTextures:@[birdTexture1, birdTexture2, birdTexture3, birdTexture4, birdTexture5, birdTexture6] timePerFrame:0.15]];
SKSpriteNode *mover = [SKSpriteNode spriteNodeWithTexture:birdTexture1];
[mover setScale:1.0];
mover.position = CGPointMake(self.frame.size.width / 2, self.size.height-120);
[mover runAction:flap withKey:@"birdGo"];
[self addChild:mover];
答案 0 :(得分:5)
尝试清理您的项目:产品 - >清洁。当您测试项目以加速编译时,XCode会缓存图像引用,这会导致奇怪的行为,尤其是在您更改图像名称时。
答案 1 :(得分:0)
您是否尝试过具有扩展名的图片文件名,如下所示?
SKTexture* birdTexture1 = [SKTexture textureWithImageNamed:@"Bird1.png"];
否则尝试其他方法,如下所示
SKTexture * texture = [SKTexture textureWithImage:[UIImage imageNamed:@"rocket.png"]];
答案 2 :(得分:0)
伙计,看看资源的名称是不是在不同的情况下,我不知道为什么,但在模拟器中,如果资源的名称是box.png和你刚刚把Box.png,它运作,但不在设备上,希望它有效。
答案 3 :(得分:0)
始终使用资源的正确路径。最好使用完整的文件名和扩展名。
请参阅最后的答案: SKTexture: Error loading image resource