2016-03-08 66 views
0

**编辑 我做了一些调试,并将名称“企鹅”更改为不存在的图像文件,奇怪的是,有时当我编译我会得到带有x的方形图标,这意味着具有该名称的文件未找到,但其他时间,此错误框甚至不会显示。奇怪的是,即使这个错误框没有显示出来(意味着程序没有尝试定位图像文件),命中检测仍然存在,并且“隐形”企鹅仍然可能死亡 **更新到Xcode 7.2.1后不加载图像

I最近从6.4版更新了我的Xcode。?到7.2.1。一旦这样做,我的一些图像将不再加载。奇怪的是,图像(在模拟器上编译游戏时)偶尔会加载,偶尔也不会显示。另外,我的SpriteKit粒子发射器也没有加载。

我的图像全部位于支持文件夹内,并标记为“[email protected]”。此外,图像全部以编程方式实例化/插入到游戏中。

Esentially我创建一个SKSpriteNode称为英雄像这样:

-(IBAction)startGame:(id)sender{ 
hero.alpha = 1; 
..... 
} 

我:

characterName = @"penguin"; 
hero = [SKSpriteNode spriteNodeWithImageNamed:characterName]; 
hero.position = CGPointMake(self.frame.size.width*0.5, self.frame.size.height*0.5); 
hero.physicsBody = [SKPhysicsBody bodyWithTexture:hero.texture size:hero.texture.size]; 
hero.physicsBody.dynamic=YES; 
hero.physicsBody.friction=NO; 
hero.physicsBody.allowsRotation=NO; 
hero.physicsBody.categoryBitMask = heroCategory; 
hero.physicsBody.contactTestBitMask = enemyCategory; 
hero.physicsBody.collisionBitMask = 0; 
hero.physicsBody.usesPreciseCollisionDetection = YES; 
hero.alpha = 0; 
[mainLayer addChild:hero]; 

然后使英雄visable,后来我在游戏开始时改变SKSpriteNode的alpha以类似的方式制作我的许多其他图像。

一个会发生什么的例子是,我第一次编译游戏时,企鹅映像可能会正确加载,然后我将停止构建并重新编译它,而企鹅将不再显示这一次,然后如果我停下来,并重建它,企鹅可能是可见再次,等等....

这我如何实现我的粒子发射器:

-(void)addFeathers: (CGPoint) position{ 
if (soundEnabled==TRUE) { 
     [poofSound play]; 
} 


NSString *explosionPath2 = [[NSBundle mainBundle] pathForResource:@"FeatherAnimation1" ofType:@"sks"]; 
SKEmitterNode *explosion2 = [NSKeyedUnarchiver unarchiveObjectWithFile:explosionPath2]; 
explosion2.position = position; 
[mainLayer addChild:explosion2]; 

SKAction *removeExposion2 = [SKAction sequence:@[[SKAction waitForDuration:10],[SKAction removeFromParent]]]; 
[explosion2 runAction:removeExposion2]; 

} 

然后在后面的程序:

if([characterName isEqualToString:@"penguin"]){ 
     [self addFeathers:deadPos]; 
    } 

该项目可以在下面的链接中找到:https://github.com/cyrusbehr/Dodge.git

我理解这个应用程序是用不好的编程习惯做,但它只是我的第一个。我真的想解决这些问题,所以我可以把游戏放回到appstore!

任何帮助,非常感谢。

回答

0

您是否尝试将图像放入资产目录?

+0

我试着把我所有的图片放在我的Images.xcassets文件夹中,但是这似乎没有解决问题。除了将图像拖入Images.xcassets文件夹以外,是否需要执行任何形式的配置(或更改任何代码)? – AppD3veloper

+0

你没有。如果您在资产目录“Player”中调用图像,而不是像SKSpriteNode(imageNamed:“Player”)那样调用它,它会自动获取正确的图像(@ 2x,@ 3x)图像。 Apple建议使用资产目录以获得最佳性能和组织。 – crashoverride777

+0

关于你的问题,很难通过查看代码来判断。你知道哪条线可能导致问题? – crashoverride777

0

尝试将图像放入资产目录; 这是因为该方法:

+ (instancetype)spriteNodeWithImageNamed:(NSString *)name; 

名称是存储在应用程序包中的图像文件的名称。

添加“.png”即可。

+0

好的,我会试试看,只是为了确认,我应该在哪里添加后缀.png? – AppD3veloper

+0

'[SKSpriteNode spriteNodeWithImageNamed:@“[email protected]”];' 并且只考虑添加@ 3x图片 – ibirdbluer

+0

我做了您所建议的更改,但我似乎仍然遇到图像仅有时会加载 – AppD3veloper

0

原来,在XCode更新后,我的背景图片阻止了我的其他节点。我通过改变背景的z位置解决了这个问题。

SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:@"sampleBackground"]; 
background.zPosition = -1.0;