增加球(物体)速度

时间:2014-02-23 14:29:08

标签: ios objective-c

我创造了简单的游戏。怎样才能提高球的速度。请帮忙!

  

- (无效)BallMovement {

        [self ComputerMovement];
        [self Collision];

        football.center = CGPointMake(football.center.x + X, football.center.y + Y);

        if (football.center.x < 15) {
            X = 0 - X;
        }

        if (football.center.x > 305) {
            X = 0 - X;
        }

        if (football.center.y < 0) {

            PlayerScoreNumber = PlayerScoreNumber + 1;
            PlayerScore.text = [NSString stringWithFormat:@"%i", PlayerScoreNumber];

            [timer invalidate];
            StartButton.hidden = NO;
            button.hidden = NO;
            football.center = CGPointMake(147, 250);

2 个答案:

答案 0 :(得分:0)

显然基于您的代码variable X是您的速度。

所以只需增加它。 (例如X + = 0.1)基于某些条件。

答案 1 :(得分:0)

  

- (无效)BallMovement {

     X=X+1

    [self ComputerMovement];
    [self Collision];

    football.center = CGPointMake(football.center.x + X, football.center.y + Y);

    if (football.center.x < 15) {
        X = 0 - X;
    }

    if (football.center.x > 305) {
        X = 0 - X;
    }

    if (football.center.y < 0) {