How to calculate the touch location with convertToWorldSpace?
- by Paul
i would like to convert the touch location as a world coordinate in my tile game. With this code, i clicked on the right of the screen (so that my character walks in the tiled game, and the background goes slowly to the left) :
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for( UITouch *touch in touches ) {
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL: location];
CGPoint test = [self convertToWorldSpace:location];
CCLOG(@"test : %.2g", test.x);
The test log gives me :
50, 72, 1e+02, 2.6e+02, 4.2e+02, (and then goes down) 3.2e+02, 9.5, -1.9e+02, etc.
Does anyone know why?
I would like to calculate the "real" coordinate of the touch, so that i know when the character has to keep going (click on the right of its actual position) or if he has to turn and go backwards. (click on the left of its actual position)
Thanks for your help