Problems with CGPoint/touches event
Posted
by Jason
on Stack Overflow
See other posts from Stack Overflow
or by Jason
Published on 2010-06-11T01:31:21Z
Indexed on
2010/06/11
10:53 UTC
Read the original article
Hit count: 287
I'm having some problems with storing variables from my touch events. The warning I get when I run this is that coord and icoord are unused, but I used them in the viewDidLoad implementation, is there a reason why this does not work? Any suggestions?
#import "iGameViewController.h"
@implementation iGameViewController
@synthesize player;
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint icoord = [touch locationInView:touch.view];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint coord = [touch locationInView:touch.view];
}
- (void)viewDidLoad {
if (coord.x > icoord.x) {
player.center = CGPointMake(player.center.x + 5, player.center.y);
}
if (coord.x < icoord.x) {
player.center = CGPointMake(player.center.x - 5, player.center.y);
}
if (coord.y > icoord.y) {
player.center = CGPointMake(player.center.x, player.center.y - 5);
}
if (coord.y < icoord.y) {
player.center = CGPointMake(player.center.x, player.center.y + 5);
}
}
Thanks.
© Stack Overflow or respective owner