开发者

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

开发者 https://www.devze.com 2023-02-28 02:26 出处:网络
I know the - (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event method but was wondering how I constantly do somet开发者_Go百科hing, such as move a sprite, while a finger is down?You could

I know the - (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event method but was wondering how I constantly do somet开发者_Go百科hing, such as move a sprite, while a finger is down?


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


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


Implement the appropriate UIGestureRecognizer subclass. You'll be sent either a begin or a changed or an ended event - and may act accordingly.

0

精彩评论

暂无评论...
验证码 换一张
取 消