In Cocos2D, how to determine what the finger is holding?

I know the event method - (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *) , but wondered how I constantly do something, for example, move the sprite until my finger works?

+4
source share
3 answers

You can do it like a gajet, or if your movement is constant, you can plan your actions. So, suppose you have this move method:

 -(void)moveSprite:(ccTime) dt { // move your sprite here by small increments } 

And then in the ccTouchBegan: method you ccTouchBegan: you plan the move method [self schedule:@selector(moveSprite:)] , and in ccTouchEnded you don't plan [self unschedule:@selector(moveSprite:)] , it will stop the movement when you finish your touch ... hope this helps

+7
source

you just need to set the boolean value to true when ccTouchBegan is ccTouchBegan and when ccTouchEnd is called set as false, then when the ccTouchMove event is ccTouchMove , you only need to check the weather whether your flag is true or not.

+5
source

Deploy the appropriate UIGestureRecognizer subclass. You will be sent either the start, or the modified or completed event - and it can act accordingly.

+2
source

All Articles