I am using UIPanGestureRecognizer to detect swipes in my app. The gesture recogniser fires correctly but when I set a variable or try to call a function from within it the variables are set but, on next iteration (of my tick function for example) the variable is not set. It is as if it is setting it on a different instance? Can anyone help me out here?
So _ApplyForce gets set to true in the handlePan function BUT it is always false when I try to read it elsewhere (in my tick function).
Update: I have added all the places _ApplyForce is used to help show how it is used. Also, the reason I use this variable to trigger off the force impulse is because of this question where I couldn't seem to trigger a force from within the gesture function, after some investigation it turned out I couldnt change or alter any class variable - hence the new question.
AppDelegate.mm:
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
....
HelloWorldLayer *layer = (HelloWorldLayer *) [[HelloWorldLayer scene].children objectAtIndex:0];
UIPanGestureRecognizer *gestureRecognizer = [[[UIPanGestureRecognizer alloc] initWithTarget:layer action:@selector(handlePanFrom:)] autorelease];
[viewController.view addGestureRecognizer:gestureRecognizer];
}
HelloWorldLayer.h
@interface HelloWorldLayer : CCLayer
{
...
bool _ApplyForce;
}
HelloWorldLayer.mm
- (id)init {
if ((self=[super init])) {
_ApplyForce = false;
}
}
- (void)tick:(ccTime) dt {
_world->Step(dt, 10, 10);
if (_ApplyForce)
{
NSLog(@"apply force");
b2Vec2 force = b2Vec2(200, 200);
_body->ApplyLinearImpulse(force,_body->GetWorldCenter());
_ApplyForce = false;
}
}
- (void)handlePanFrom:(UIPanGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateEnded) {
_ApplyForce=true;
}
}
_ApplyForcedeclared ? are sure nothing else is altering the value ? - user756245BOOL? this is really strange - user756245