我正在使用 cocos2d-x 在 xcode 中创建游戏。我是 cocos2d-x 的新手。
我创建了两个CCControlButton
用于跳转和滑动的按钮。我为运行和滑动创建了动画,名称相同,名为 man。
对于我在 init() 中创建的运行和对于我在名为旋转的单独函数中创建的幻灯片。当我按下幻灯片按钮时,幻灯片动画正在运行,当我释放运行动画时正在运行。
当我按住滑动按钮时,滑动动画应该保持滑动,当我释放滑动按钮时,滑动动画应该停止并运行动画应该运行,但是当释放滑动按钮时,跳转按钮不起作用,因为我给出了一个只有if(man->numberofrunningaction()==1)
它应该跳转的条件.
当我按下幻灯片时,动作的数量正在增加。任何人都请帮我找到解决方案。
我正在使用以下代码跳转,幻灯片动画和运行动画..
void PlayScene::rotate()
{
anim1=CCAnimation::create();
anim1->addSpriteFrameWithFileName("11.png");
anim1->addSpriteFrameWithFileName("11.png");
anim1->addSpriteFrameWithFileName("11.png");
anim1->setLoops(4);
anim1->setDelayPerUnit(0.05f);
man->runAction(CCAnimate::create(anim1));
man->setPosition(ccp(winwsize/5.5,winhsize/2.2));
CCRotateBy *rot=CCRotateBy::create(1, 0.000000001);
man->runAction(rot);
}
init()
man=CCSprite::create();
man->retain();
anim=CCAnimation::create();
anim->retain();
anim->addSpriteFrameWithFileName("1.png");
anim->addSpriteFrameWithFileName("2.png");
anim->addSpriteFrameWithFileName("3.png");
anim->addSpriteFrameWithFileName("4.png");
anim->addSpriteFrameWithFileName("5.png");
anim->addSpriteFrameWithFileName("6.png");
anim->addSpriteFrameWithFileName("7.png");
anim->addSpriteFrameWithFileName("8.png");
anim->addSpriteFrameWithFileName("9.png");
anim->setLoops(-1);
anim->setDelayPerUnit(0.05f);
man->runAction(CCAnimate::create(anim));
man->setPosition(ccp(winwsize/5.5,winhsize/2.2));
this->addChild(man,1);
creating button for jump & slide.
CCControlButton *rotate = CCControlButton::create(CCScale9Sprite::create("jump1.png"));
rotate->setAdjustBackgroundImage(false);
rotate->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 70,70) );
rotate>addTargetWithActionForControlEvents(this,cccontrol_selector
(PlayScene::jumpfun),CCControlEventTouchDown);
addChild(rotate, 3);
CCControlButton *jumpbutton=CCControlButton::create(CCScale9Sprite::create("slide2.png"));
jumpbutton->setAdjustBackgroundImage(false);
jumpbutton->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 250,70) );
jumpbutton->addTargetWithActionForControlEvents(this,
cccontrol_selector(PlayScene::rotate),CCControlEventTouchDown);
jumpbutton->addTargetWithActionForControlEvents(this, cccontrol_selector
(PlayScene::buttonup),CCControlEventTouchUpInside);
addChild(jumpbutton, 3);
void PlayScene::buttonup()
{
anim1->setLoops(0);
}