I'm still having trouble implementing this callback method in my sequence - Maybe someone can help me with an if statement not allowing another action to be initiated during the first running action - I really need someone to walk me through this ;-)
touch dispatcher for dummies?
(44 posts) (7 voices)-
Posted 1 year ago #
-
anyone, pls :---(
Posted 1 year ago # -
Can someone tell me if Im thinking in the right direction
if I add the following statement:
if (TouchEnded == NO) return NO;it should not initiate the a new touch until the action has completed?
But how do I declare this function for the first time?PS I know my questions are really simple but I just don't know.
Posted 1 year ago # -
You are on the right track but I think most people would just code TouchEnded as a simple BOOL rather than a function. If it was a function you'd need [self TouchEnded] or a property would be self.TouchEnded.
What programming language(s) do you have experience in, it seems like you are struggling with basic programming concepts that have nothing to do with cocos2d or even Objective C.
Posted 1 year ago # -
Thanks, mate.
I'm just learning Objective C. I work in education and work with people and the only limited IT experience I have is in mysql and php :-(
Cocos2d/iphone is just a hobby for me now.Posted 1 year ago # -
Is it making sense now? Did you get your callFunc working? It may be easier if you post your code.
Unfortunately I don't know php so I can't explain things in those terms.
Posted 1 year ago # -
I'm just messing around with the TouchesTest demo and the states. What I want to do is have the paddle return to its original state and location after the touch is ended (finger taken off the screen) Right now each touch causes the paddle to be scaled but double tapping just reinitiates it even if it is in the middle of the scaling action.
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event { if (state != kPaddleStateUngrabbed) return NO; if ( ![self containsTouchLocation:touch] ) return NO; state = kPaddleStateGrabbed; id actionBy = [ScaleBy actionWithDuration: 1.0f scale: 2.0f]; id actionByBack = [actionBy reverse]; ; [self runAction: [Sequence actions:actionBy, actionByBack, nil]]; return kEventHandled; return YES; }As you can see from the demo there isn't much that I have done except add the action - I just don't know how to limit this action.
Also, I gave up on callFunc :-(Posted 1 year ago # -
Do you still have this code from TouchesTest?
- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event { NSAssert(state == kPaddleStateGrabbed, @"Paddle - Unexpected state!"); state = kPaddleStateUngrabbed; }See how the state is used as a guard in ccTouchBegan but when the touch ended the state is changed back to allow the touch began code to run again? What you need to do is only change the state back to kPaddleStateUngrabbed when your action ends and unfortunately the best way to do that is with a callFunc to a method that sets state = kPaddleStateUngrabbed. So jump back on the callFunc horse and post your code if it doesn't work.
Posted 1 year ago # -
I'm embarrassed to say this but the more I look at the SpritesTest example with CallFunc the less I understand. I am truly losing my mind here. I've tried so many different versions of my action with CallFunc. I would really need to see another working example of CallFunc... SOS
Posted 1 year ago # -
^ Did you look in the Wiki, it seems pretty clear to me. Just use the first model and change the state to kPaddleStateUngrabbed in the doATask method. Don't forget to comment out that state change in ccTouchEnded if you still have it too.
http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:actions_special
Posted 1 year ago # -
OK I had a look before in the day but this is what I've added now:
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event { if (state != kPaddleStateUngrabbed) return NO; if ( ![self containsTouchLocation:touch] ) return NO; state = kPaddleStateGrabbed; id actionBy = [ScaleBy actionWithDuration: 1.0f scale: 2.0f]; id actionByBack = [actionBy reverse]; id actionCallFunc = [CallFunc actionWithTarget:self selector:@selector(kPaddleStateUngrabbed)]; id actionSequence = [Sequence actions: actionBy, actionByBack, actionCallFunc, nil]; [self runAction: actionSequence]; return kEventHandled; return YES; } -(void)kPaddleStateUngrabbed { NSAssert(state == kPaddleStateGrabbed, @"Paddle - Unexpected state!"); state = kPaddleStateUngrabbed; }It builds OK but the paddle doesn't seem to revert to its initial state and many consecutive touches just makes it crash.
:-(Posted 1 year ago # -
Get rid of that "return kEventHandled" and make sure state is not being set anywhere else. If it crashes then where and why? What is printed in the console?
Posted 1 year ago # -
OK I got rid of that and also the
- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event { NSAssert(state == kPaddleStateGrabbed, @"Paddle - Unexpected state!"); state = kPaddleStateUngrabbed; }which was at the end and was causing the crash.
Thank you so much - no more dumb questions - at least for today wink-wink!
Posted 1 year ago # -
Congratulations, I admire your perseverance. Hopefully things will get easier.
Posted 1 year ago #
Reply
You must log in to post.