简体   繁体   中英

How to make a sprite jump using CCJumpTo in cocos2d-x

I am new to cocos2d-x and I am developing a game in xcode using cocos2d-x 2.0.4. In that I want to make my sprite jump.So that i use the following code. Using that code it is working, but the problem is if i tab the screen continuously the sprite is keep on jumping(like flying). But i want my sprite should not jump until the first jump finished. Following is code,

void PlayScene::ccTouchesBegan(cocos2d::CCSet* pTouches, cocos2d::CCEvent* pEvent)
{
CCTouch* touch = (CCTouch* )pTouches->anyObject();
CCPoint location = touch->locationInView();
location = CCDirector::sharedDirector()->convertToGL(location);
 CCJumpTo *pJumpTo = new CCJumpTo();
pJumpTo->initWithDuration(1, ccp(winwsize/5.5,winhsize/2.2), 100, 1);
man->runAction(pJumpTo);
}

Please help me to solve it.

You should check if there are any running actions on your man sprite. This can be done easily by calling man->numberOfRunningActions() - if this is not 0 you shouldn't start new action.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM