在 Xcode-Objective C 中使用 Sprite Kit 在世界场景中放错了 Spritenode
Spritenode misplaced in World Scene using Sprite Kit in Xcode-Objective C
我正在使用 Sprite Kit 在 Xcode 6.0 中构建平台游戏。我遇到的问题与通过以下方法创建的 "monster sprite node" 有关
-(void) generateMonster {
monster = [SKSpriteNode spriteNodeWithImageNamed:@"monster.png"];
monster.name = @"monster";
monster.size = CGSizeMake(monster.frame.size.width, monster.frame.size.height);
monster.position = CGPointMake(self.currentMonsterX, ground.position.y + monster.frame.size.height);
monster.zPosition = 3.0;
monster.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:monster.size];
monster.physicsBody.categoryBitMask = monsterCategory;
SKAction *moveRight = [SKAction moveByX:30.0 y:0 duration:1.0];
SKAction *moveLeft = [SKAction moveByX:-30.0 y:0 duration:0.5];
SKAction *pulseMovement = [SKAction sequence:@[moveRight, moveLeft]];
[monster runAction:[SKAction repeatActionForever:pulseMovement]];
[self.world addChild:monster];
self.currentMonsterX += (arc4random() % 400) + 100;
}
调试中怪物的位置是可以的"about 50.0",但是当它放置到另一个SKNode *World 包含所有其他内容如云彩,星星和英雄时,monster.position.y得到一个负值使其低于 "about -9000"!!?
感谢任何帮助。
我的坏..
我在创建顺序上有一点逻辑错误。这就是我正在做的,以防万一其他人陷入同样的错误。
问题出在代码行中:
monster.position = CGPointMake(self.currentMonsterX, ground.position.y + monster.frame.size.height);
恰好在 "ground.position.y",因为节点 "ground" 尚未创建,因此怪物正在掉落,因此 -9000 或更低。
对此感到抱歉。
我正在使用 Sprite Kit 在 Xcode 6.0 中构建平台游戏。我遇到的问题与通过以下方法创建的 "monster sprite node" 有关
-(void) generateMonster {
monster = [SKSpriteNode spriteNodeWithImageNamed:@"monster.png"];
monster.name = @"monster";
monster.size = CGSizeMake(monster.frame.size.width, monster.frame.size.height);
monster.position = CGPointMake(self.currentMonsterX, ground.position.y + monster.frame.size.height);
monster.zPosition = 3.0;
monster.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:monster.size];
monster.physicsBody.categoryBitMask = monsterCategory;
SKAction *moveRight = [SKAction moveByX:30.0 y:0 duration:1.0];
SKAction *moveLeft = [SKAction moveByX:-30.0 y:0 duration:0.5];
SKAction *pulseMovement = [SKAction sequence:@[moveRight, moveLeft]];
[monster runAction:[SKAction repeatActionForever:pulseMovement]];
[self.world addChild:monster];
self.currentMonsterX += (arc4random() % 400) + 100;
}
调试中怪物的位置是可以的"about 50.0",但是当它放置到另一个SKNode *World 包含所有其他内容如云彩,星星和英雄时,monster.position.y得到一个负值使其低于 "about -9000"!!?
感谢任何帮助。
我的坏.. 我在创建顺序上有一点逻辑错误。这就是我正在做的,以防万一其他人陷入同样的错误。
问题出在代码行中:
monster.position = CGPointMake(self.currentMonsterX, ground.position.y + monster.frame.size.height);
恰好在 "ground.position.y",因为节点 "ground" 尚未创建,因此怪物正在掉落,因此 -9000 或更低。
对此感到抱歉。