user1725997
user1725997

Reputation:

iOS Touch Not Working On Hold

apologies in advance for the noob question. yet im very new to iOS development.

i have followed a simple Pong tutorial from here: http://www.technobuffalo.com/companies/apple/introduction-to-ios-development-programming-pong-part-4/

i have managed to debug and get the app working, yet i only seem to be able to move the player paddle when 're-touching' the screen.

i.e. paddle does not follow finger movement when held down on the screen.

from what i understand, the following is the method which controls the touch events:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
self.gameState = kGameStateRunning;

if (location.x > 400) {
    CGPoint yLocation = CGPointMake(playerPaddle.center.x, location.y);
    playerPaddle.center = yLocation;
}
}

can anyone please help shed some light on what the issue may be?

many many thanks in advance :)

Upvotes: 0

Views: 201

Answers (1)

Fry
Fry

Reputation: 6275

You are wrong ! You shouldn't use

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

As the name says this detect only the finger touch the screen. You should use

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

Upvotes: 1

Related Questions