I am building a platform game in Xcode 6.0 using Sprite Kit. The problem that I have is related to the "monster sprite node" which are created by the following method
-(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;
}
the position of monster in the debugging is OK "about 50.0", but when it placed to the other SKNode *World which contains all other contents like clouds, stars and hero, the monster.position.y gets a negative value which moves it way below "about -9000"!!?
Any help is appreciated.
My bad .. I had a little logic mistake in the order of creation .. Here is what I was doing, just in case someone else stuck with the same mistake.
The problem was in the code line:
monster.position = CGPointMake(self.currentMonsterX, ground.position.y + monster.frame.size.height);
Precisely at "ground.position.y" since the node "ground" was not yet created and hence the monsters were falling and thus the -9000 or lower.
Sorry about that.