0

私は現在、タッチの開始と移動時にプレーヤーを移動できるジョイパッドを使用しています。問題は、ジョイパッドに触れて、指を動かしたり離したりせずに触れ続けた場合、プレーヤーを動かし続けるにはどうすればよいですか? ここにいくつかのコードがあります:

- (void)updateVelocity:(CGPoint)point {


    // Calculate distance and angle from the center. 

    CGRect frame = _player.image.frame;

    float dx = point.x - padCenter.x;
    float dy = point.y - padCenter.y;

    frame.origin.x += dx/10;
    frame.origin.y += dy/10;

    if (!(frame.origin.x < 0 || frame.origin.y < 0 || frame.origin.x > SCREEN_SIZE_X - frame.size.width || frame.origin.y > SCREEN_SIZE_Y - frame.size.height)) //if the players won't exit the screen then move it
    _player.image.frame = frame;
}

これはプレイヤーを動かすためのものです。

そして、これはタッチが始まった/動いたときです

-(void)touchesBegan :(CGPoint )point{ //same as moved

    if (isPointInCircle(point, padCenter , JOYSTICK_RADIUS)){
        isPressed = YES;
        [self updateVelocity:point];
    }
}

ビューコントローラーの touchesBegan メソッドは次のとおりです。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ //same as Moved

    UITouch *touch = [touches anyObject];
    CGPoint point = [touch locationInView: [touch view]];
    [joypad touchesBegan:point];

}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    [joypad touchesEnded];
}

先ほど言ったように、指を動かさずにジョイパッドの領域をタッチすると、プレイヤーは 1 回だけ動きます。指を離すまで動かし続けるためのアイデアはありますか?

4

1 に答える 1