At around the 18:16 point in the Pong video, the professor is able to get the log to report back whether the user touches the left, middle, or right of the screen. However, my attempts with the same code yield left for over three quarters of the screen, the response that should be for the center on the right quarter, and I am unable to get it to return the response for a right side touch. Has anybody run into this issue that can help me understand what I’ve done wrong?
It is probably in the logic for handling the touch. Use the debug tools to put a breakpoint in the touch callback code so that you can see if you are getting a callback when the part of the screen you are worried about is touched.
I have the same problem…left working great, can’t figure out why right is not…
its like left works for 3/4 of the screen, then its empty, and no right…
The code looks right, I don’t get it why is it not behaving like it should…
-
(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *t in touches) {
CGPoint p = [t locationInNode:self];
NSLog(@"\n%f %f %f %f", p.x, p.y, self.frame.size.width, self.frame.size.height);if(p.x < self.frame.size.width * 0.3){ self.leftPaddleMotivatingTouch = t; NSLog(@"left"); } else if(p.x > self.frame.size.width * 0.7){ self.rightPaddleMotivatingTouch = t; NSLog(@"right"); } else { // if ball gets stuck, we increase the velocity by doubling it SKNode *ball = [ self childNodeWithName:@"ball"]; ball.physicsBody.velocity = CGVectorMake(ball.physicsBody.velocity.dx*2.0, ball.physicsBody.velocity.dy); }
}
[self trackPaddlesToMotivatingTouches];
}
Have you found the solution for this?
I’ve tried different sizes in GameScene.sks, I used Custom, or iPad 9.7", iPhone 6 Plus…, the behavior is always the same
Thanks,
Mircea
The only way I made it kind of work, is to use this code
if(p.x < self.frame.size.width * 0.01){
self.leftPaddleMotivatingTouch = t;
NSLog(@“left”);
} else if(p.x > self.frame.size.width * 0.1){
self.rightPaddleMotivatingTouch = t;
NSLog(@“right”);
}
Like that I get left for first half of the screen and right for the other… and a bit in the middle I get nothing, so I can use it to increase the velocity…
But still it doen’t make sense why is acting this way…