改变Sprite Spawns

时间:2014-03-18 03:46:24

标签: ios iphone sprite

这是我在下面使用的代码,我希望它在纵向模式下从x轴的底部生成,现在在纵向模式中从顶部生成如何编辑代码来执行此操作? / p>

- (void)addBalloon {

        // Create sprite
        SKSpriteNode * monster = [SKSpriteNode spriteNodeWithImageNamed:@"balloon"];

        // Determine where to spawn the monster along the X axis
        int minX = monster.size.width / 2;
        int maxX = self.frame.size.width - monster.size.width / 2;
        int rangeX = maxX - minX;
        int actualX = (arc4random_uniform(rangeX)) + minX;

        // Create the monster slightly off-screen along the top,
        // and along a random position along the X axis as calculated above
        monster.position = CGPointMake(actualX, self.frame.size.height +  
 monster.size.height/2);
        [self addChild:monster];

        // Determine speed of the monster
        int minDuration = 2.0;
        int maxDuration = 4.0;
        int rangeDuration = maxDuration - minDuration;
        int actualDuration = (arc4random() % rangeDuration) + minDuration;

        // Create the actions
        SKAction * actionMove = [SKAction moveTo:CGPointMake(actualX, -
monster.size.height/2) duration:actualDuration];
        SKAction * actionMoveDone = [SKAction removeFromParent];
        [monster runAction:[SKAction sequence:@[actionMove, actionMoveDone]]];

}

1 个答案:

答案 0 :(得分:1)

我不确定你在这里问的是什么。你想在 X -axis的底部生成一个精灵? 如果它是我认为你要问的,你只需要切换:

monster.position = CGPointMake(actualX, self.frame.size.height + monster.size.height/2);

&安培;&安培;

SKAction * actionMove = [SKAction moveTo:CGPointMake(actualX, - monster.size.height/2) duration:actualDuration];

使用:

monster.position = CGPointMake(actualX, - monster.size.height/2);

&安培;&安培;

SKAction * actionMove = [SKAction moveTo:CGPointMake(actualX, self.frame.size.height + monster.size.height/2) duration:actualDuration];