Cocos2dx 动作篇二(ScaleTo & ScaleBy)

Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();


Sprite * sp1 = Sprite::create("HelloWorld.png");
sp1->setPosition(Point(150, visibleSize.height / 2));
sp1->setScale(2.0f);
this->addChild(sp1);

Sprite * sp2 = Sprite::create("HelloWorld.png");
sp2->setPosition(Point(600, visibleSize.height / 2));
sp2->setScale(2.0f);
this->addChild(sp2);

//拉伸动作
////////////////////////////////动作执行的时间,x轴拉伸的倍数,y轴拉伸的倍数
ScaleTo * scaleto = ScaleTo::create(2.8f, 0.4f, 1.0f);
////////////////////////////////动作执行的时间,x轴拉伸的倍数,y轴拉伸的倍数
ScaleBy * scaleby = ScaleBy::create(2.8f, 0.4f, 1.0f);
sp1->runAction(scaleto);

sp2->runAction(scaleby);

ScaleTo & ScaleBy的区别是:ScaleTo不管你原先是否对精灵进行拉伸,只是在原精灵的基础上拉伸指定倍数,ScaleBy是考虑到原来对精灵的拉伸,把原来精灵拉伸的倍数也算到拉伸动画的倍数里面去,个中缘由大家一试就会非常清楚。

你可能感兴趣的:(cocos2dx)