CCJumpTo和CCJumpBy属于延时动作,即经过一段时间才能完成的动作
CCJumpTo:把某一CCSprite跳到某一位置
CCJumpBy:把某一CCSprite跳起一段距离,它有一个方法reverse,它让对象按原路径返回
创建一个Layer来实验这两个类的使用,然后直接在前面创建的GameScene初始化TestLayer并添加为子节点,即可看到效果
class TestLayer : public CCLayer
{
public:
TestLayer();
~TestLayer();
virtual bool init();
void play();
CREATE_FUNC(TestLayer);
protected:
CCSprite * m_sprite;
};
bool TestLayer::init()
{
CCTexture2D *heroTex=CCTextureCache::sharedTextureCache()->addImage("hero.png");
CCSpriteFrame * frame0,*frame1,*frame2,*frame3;
frame0=CCSpriteFrame::createWithTexture(heroTex,CCRectMake(32*0,0*32,32,32));
m_sprite=new CCSprite();
m_sprite->initWithSpriteFrame(frame0);
m_sprite->setPosition(ccp(100,100));
this->addChild(m_sprite);
return true;
}
void TestLayer::play()
{
CCActionInterval* actionTo = CCJumpTo: