Hey all,
I was hoping someone might be able to enlighten me on this issue.
Basically I have a bunch of sprites and need to detect when a touch starts/ends on one of them.
No problems there, but the player can pan the screen by swiping 2 fingers across, thus moving the camera of the layer.
So for the movement aspect of things, I use this code:
CGPoint location = [touch locationInView: [touch view]];
location = [[Director sharedDirector] convertCoordinate: location];
float centerX, centerY, centerZ;
float eyeX, eyeY, eyeZ;
[self.camera centerX:¢erX centerY:¢erY centerZ:¢erZ];
[self.camera eyeX:&eyeX eyeY:&eyeY eyeZ:&eyeZ];
location.x+=(centerX-160);
location.y+=(centerY-240);
and it works fine.
The issue is that I'm also changing the Z value, and cannot get that to work.
Is there perhaps an easier way of doing this?
Basically I need to "convert" the touch coordinate based on the Z value of the camera, I tried this:
location.x = location.x * (eyeZ / 416 );
location.y = location.y * (eyeZ / 416 );
416 seems to be the default value for a 1:1 camera, so I'm basing the calculations on that, but I can't get it to work although I've tried many other variants.
If a part of screen is visible that should be <0 coordinate, the touch will still obviously give a positive value because it's relative to the screen.
Hopefully someone can help me out here!
Thanks
Patrick
PS: Upon further investigation, I see this was discussed in January on the old forum but couldn't find any folllowups. Basically I need to convert my coordinate based on the layer's position/scale (not rotation).