MoveTo:把某一CCSprite移动到某个位置
MoveBy:把某一CCSprite移动一段距离,它有一个方法reverse,它让对象按原路径返回
void MyActionMoveToLayer::initLayer() {
/*
*@MoveTo,移动到某个Point
*/
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCSprite *spriteMoveTo = CCSprite::create("snow.png");
spriteMoveTo->setPosition(ccp(size.width / 2.0f, size.height / 2.0f));
this->addChild(spriteMoveTo, 1);
CCActionInterval *forward = CCMoveTo::create(4, ccp(300, 300));
spriteMoveTo->runAction(forward);
/*
*MoveBy,移动一段距离
*/
CCSprite *spriteMoveBy = CCSprite::create("snow.png");
spriteMoveBy->setPosition(ccp(size.width / 4.0f, size.height / 4.0f));
this->addChild(spriteMoveBy, 1);
CCActionInterval *forwardBy = CCMoveBy::create(2, ccp(200, 300));
CCActionInterval *backBy = forwardBy->reverse();
CCAction *action = CCRepeat::create(dynamic_cast<CCFiniteTimeAction *>(CCSequence::create(forwardBy, backBy, NULL)), 4);
spriteMoveBy->runAction(action);
}