Problems with CGPoint/touches event
- by Jason
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.