【发布时间】:2014-02-04 09:43:49
【问题描述】:
我正在尝试将精灵制作为青蛙,它将从屏幕顶部出现并在 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);
}
【问题讨论】:
-
CCJumpTo 和 CCJumpBy 方法用于跳跃精灵而不是 CCMoveTo。
-
我想让青蛙在每次跳跃后休息一秒钟。你能帮我吗?
-
id 延迟 = [CCDelayTime actionWithDuration:1.0];那是客观 c,但你在 C++ 中使用相同的方法。
-
先生,这是主要问题..延迟的地方..看看我的 CCMoveto 线...
-
z->runAction(CCSequence::create(CCMoveTo::create(2.0, ccp(winSize.width/2, 0)), CCCallFuncN::create(this, callfuncN_selector(HelloWorld::setInvisible) )), NULL));