我正在尝试制作一个精灵作为青蛙,它将来自屏幕的顶部,并将向下移动到y轴= 0的底部。它正常工作正常CCMoveTo但我希望在跳跃之后青蛙应该休息1秒然后再跳。有些延迟移动。任何人都可以告诉我这个。我也附上我的代码。 我的青蛙动画是从fly1.png到fly5.png。我只是想在每次移动后延迟,或者我们可以说我只想在每次延迟1秒后调用CCMove,直到青蛙到达y轴= 0 任何帮助将不胜感激。谢谢
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
using namespace cocos2d;
using namespace CocosDenshion;
CCScene* HelloWorld::scene()
{
CCScene *scene = CCScene::create();
HelloWorld *layer = HelloWorld::create();
scene->addChild(layer);
return scene;
}
bool HelloWorld::init()
{
if ( !CCLayer::init() )
{
return false;
}
CCSize winSize=CCDirector::sharedDirector()->getWinSize();
_bgNode = CCNode::create();
_bgNode->setPosition(ccp(winSize.width/2, winSize.height/2));
this->addChild(_bgNode, -1);
_bgSprite = CCSprite::create("bg_2.jpg");
_bgNode->addChild(_bgSprite);
float rX = winSize.width/_bgSprite->getContentSize().width;
float rY = winSize.height/_bgSprite->getContentSize().height;
_bgNode->setScaleX(rX);
_bgNode->setScaleY(rY);
z=CCSprite::create("fly1.png");
z->setScaleX(rX);
z->setScaleY(rY);
z->setPosition(ccp(winSize.width/2,winSize.height+1));
this->addChild(z);
CCAction *a=CCRepeatForever::create(HelloWorld::getAnimationWithFrames(1,5));
z->runAction(a);
z->runAction(CCSequence::create(CCMoveTo::create(2.0, ccp(winSize.width/2, 0)), CCCallFuncN::create(this, callfuncN_selector(HelloWorld::setInvisible)), NULL));
return true;
}
cocos2d::CCAnimate* HelloWorld::getAnimationWithFrames(int from, int to)
{
CCArray* frames = CCArray::create();
for (int i = from; i <= to; i++)
{
CCString *str = CCString::createWithFormat("fly2%d.png", i);
CCSpriteFrame *f = CCSpriteFrame::create(str->getCString(), CCRect(0,0,256,400));
frames->addObject(f);
}
//(frames,speedofmovementofanimation);
CCAnimation *animation = CCAnimation::createWithSpriteFrames(frames,0.15f);
CCAnimate *a = CCAnimate::create(animation);
return a;
}
void HelloWorld::setInvisible()
{
this->removeChild(z,true);
}
答案 0 :(得分:0)
Firstly, you have to create a frogJump() function. Then,in frogJump() function add the following code:
void HelloWorld::frogJump()
{
CCJumpTo* jumpTo = CCJumpTo::create(1,ccp(x/6,y/8),y/1.2f,1);
z->runAction(jumpTo);
}
Then, in the init() function add the following line:
this->scheduleOnce(SEL_SCHEDULE(&HelloWorld::frogJump),0);
this->schedule(SEL_SCHEDULE(&HelloWorld::frogJump),2);