Hi there
I developing an iPhone game and having some problem now, could anyone help me out ?
I want to open a thing on the screen, the item in the centre of the screen, and I need 2 fingers to open it. Just put 2 fingers in and move horizontally to the certain points then let go, then the thing opens. I am making a range for the points. Because it is horizontal, so x is always changing so i don quite care for x, so do a range for y.
float rangeY = location3.y - location.y;
then i put the rangeY in a value, so if my 2 fingers move out of the range it will show error. But now however i move my 2 fingers it also says successful. Maybe my conditions are incorrect, could any experts take a look at my code and tell me why.
-(BOOL)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)events
{
NSInteger touchCount = 0;
//float rangeOfDistance = 0.0;
NSSet *allTouches3 = [events allTouches];
for( UITouch *touch in allTouches3)
{
location3 = [touch locationInView: [touch view]];
location3 = [[Director sharedDirector] convertCoordinate: location3];
NSLog(@"end TOUCHed x2: %3.3f, y2: %3.3f",location3.x,location3.y);
touchCount++;
}
//location is the points made when just put down the fingers, it is in the ccTouchesBegan
float rangeY = location3.y - location.y;
if (touchCount > 0 && touchCount ==2)
{
if (rangeY != 0.0 && rangeY < 10.0)
[self loadBoxOpenedScene];
}
else
{
NSLog(@"wrong direction");
}
return kEventHandled;
}