Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Cocos2D how do I detect that finger is being held down?

I know the - (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event method but was wondering how I constantly do something, such as move a sprite, while a finger is down?

like image 891
Adam Ashwal Avatar asked Dec 09 '22 09:12

Adam Ashwal


1 Answers

You could do it like Gajet or if your motion is constant you can schedule your actions. So assume you have this move method:

-(void)moveSprite:(ccTime) dt {

  // move your sprite here by small increments
}

And then in ccTouchBegan: method you mentioned, you schedule the move method [self schedule:@selector(moveSprite:)] and in ccTouchEnded you unschedule [self unschedule:@selector(moveSprite:)] this will stop the motion when you end your touch... Hope this helps

like image 99
KDaker Avatar answered Dec 14 '22 23:12

KDaker