当检测到某个碰撞时,我收到 sigabrt 错误(iOS,SpriteKit)
I'm getting a sigabrt error when a certain collision is detected (iOS, SpriteKit)
我目前正在 Objective-C 中构建一个 iOS 应用程序。该应用程序的想法是,你有某种火箭飞船在某种小行星带中航行。它以纵向模式播放。有两种不同类型的小行星。普通的一撞就输,金色的射一枪拿金币。
现在,当检测到子弹和金色小行星之间发生碰撞时,就会出现问题。当检测到玩家与一颗普通小行星发生碰撞时,一切都很好,而你输了。但是当检测到子弹和金色小行星之间发生碰撞时,我收到一个 sigabrt 错误。
检测碰撞的代码代码如下:
- (void)didBeginContact:(SKPhysicsContact *)contact
{
uint32_t collision = (contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask);
if (collision == (playerCategory | asteroidCategory))
{
[self player:(SKSpriteNode *)self.player didCollideWithAsteroid:(SKSpriteNode *)self.asteroid];
}
uint32_t collision2 = (contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask);
if (collision2 == (bulletCategory | goldAsteroidCategory))
{
[self bullet:(SKSpriteNode *)self.bullet didCollideWithGoldAsteroid:(SKSpriteNode *)self.goldAsteroid];
}
}
当“[self player:(SKSpriteNode *)self.player didCollideWithAsteroid:(SKSpriteNode *)self.asteroid];”时运行的代码被称为是这样的:
- (void)player:(SKSpriteNode *)player didCollideWithAsteroid:(SKSpriteNode *)asteroid
{
[self runAction:[SKAction playSoundFileNamed:@"Explosion.mp3" waitForCompletion:NO]];
NSLog(@"Hit");
[self.player removeFromParent];
[self.asteroid removeFromParent];
SKAction *actionMoveDone = [SKAction removeFromParent];
SKAction * loseAction = [SKAction runBlock:^{
SKTransition *reveal = [SKTransition crossFadeWithDuration:0.5];
SKScene * gameOverScene = [[GameOverScene alloc] initWithSize:self.size won:NO];
[self.view presentScene:gameOverScene transition: reveal];
}];
[self.asteroid runAction:[SKAction sequence:@[loseAction, actionMoveDone]]];
}
这是在“[self bullet:(SKSpriteNode *)self.bullet didCollideWithGoldAsteroid:(SKSpriteNode *)self.goldAsteroid];”时运行的代码被称为:
- (void)bullet:(SKSpriteNode *)bullet didCollideWithGoldAsteroid:(SKSpriteNode *)goldAsteroid
{
[self runAction:[SKAction playSoundFileNamed:@"ding.m4a" waitForCompletion:NO]];
NSLog(@"Hit");
[self.bullet removeFromParent];
[self.goldAsteroid removeFromParent];
[self plusOneCoin];
}
我相信这应该是足够的信息和代码,但不要犹豫向我询问更多,我会 post 需要什么。
当我查看日志时,我发现音效有问题"ding.m4a"。我将其替换为另一种硬币声音,现在可以使用了。我不确定声音是怎么回事,但这就是问题所在。
我目前正在 Objective-C 中构建一个 iOS 应用程序。该应用程序的想法是,你有某种火箭飞船在某种小行星带中航行。它以纵向模式播放。有两种不同类型的小行星。普通的一撞就输,金色的射一枪拿金币。
现在,当检测到子弹和金色小行星之间发生碰撞时,就会出现问题。当检测到玩家与一颗普通小行星发生碰撞时,一切都很好,而你输了。但是当检测到子弹和金色小行星之间发生碰撞时,我收到一个 sigabrt 错误。
检测碰撞的代码代码如下:
- (void)didBeginContact:(SKPhysicsContact *)contact
{
uint32_t collision = (contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask);
if (collision == (playerCategory | asteroidCategory))
{
[self player:(SKSpriteNode *)self.player didCollideWithAsteroid:(SKSpriteNode *)self.asteroid];
}
uint32_t collision2 = (contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask);
if (collision2 == (bulletCategory | goldAsteroidCategory))
{
[self bullet:(SKSpriteNode *)self.bullet didCollideWithGoldAsteroid:(SKSpriteNode *)self.goldAsteroid];
}
}
当“[self player:(SKSpriteNode *)self.player didCollideWithAsteroid:(SKSpriteNode *)self.asteroid];”时运行的代码被称为是这样的:
- (void)player:(SKSpriteNode *)player didCollideWithAsteroid:(SKSpriteNode *)asteroid
{
[self runAction:[SKAction playSoundFileNamed:@"Explosion.mp3" waitForCompletion:NO]];
NSLog(@"Hit");
[self.player removeFromParent];
[self.asteroid removeFromParent];
SKAction *actionMoveDone = [SKAction removeFromParent];
SKAction * loseAction = [SKAction runBlock:^{
SKTransition *reveal = [SKTransition crossFadeWithDuration:0.5];
SKScene * gameOverScene = [[GameOverScene alloc] initWithSize:self.size won:NO];
[self.view presentScene:gameOverScene transition: reveal];
}];
[self.asteroid runAction:[SKAction sequence:@[loseAction, actionMoveDone]]];
}
这是在“[self bullet:(SKSpriteNode *)self.bullet didCollideWithGoldAsteroid:(SKSpriteNode *)self.goldAsteroid];”时运行的代码被称为:
- (void)bullet:(SKSpriteNode *)bullet didCollideWithGoldAsteroid:(SKSpriteNode *)goldAsteroid
{
[self runAction:[SKAction playSoundFileNamed:@"ding.m4a" waitForCompletion:NO]];
NSLog(@"Hit");
[self.bullet removeFromParent];
[self.goldAsteroid removeFromParent];
[self plusOneCoin];
}
我相信这应该是足够的信息和代码,但不要犹豫向我询问更多,我会 post 需要什么。
当我查看日志时,我发现音效有问题"ding.m4a"。我将其替换为另一种硬币声音,现在可以使用了。我不确定声音是怎么回事,但这就是问题所在。