I just don’t want to regret it:
1.
你想去哪,你想走多远 ——MoveTo和MoveBy:
MoveTo(你想去哪)它的作用也就是从某个地方到另一个地方,比如A(x1, y1),B(x2, y2
);当我们想把精灵从A移动到B点时,我们就可以用MoveTo(A MoveTo B,就是这么理解啦~)。
MoveBy(你想走多远)它的作用就是A运动B这个距离这么远。也就是到达C(x1 + x2, y1 + y2);(A add B,就这么理解~)
具体实现如下:
//截取屏幕大小 Size visibleSize = Director::getInstance()->getVisibleSize(); //定义一个精灵 Sprite* Roope = Sprite::create("sprite.png"); Roope->setPosition(Point(50,visibleSize.height / 2));//放置的位置 this->addChild(Roope); //你想去哪 //MoveTo* moveTo = MoveTo::create(0.9f,Point(250,150)); //Roope->runAction(moveTo); //你想走多远 MoveBy* moveBy = MoveBy::create(0.9f,150)); Roope->runAction(moveBy);
2
.
我要减肥——ScaleTo和ScaleBy:
首先是ScaleTo,ScaleTo的create有三个参数:
float duration: 动作的持续时间,单位为秒。
float sx : x方向的拉伸值。
float sy : y方向的拉伸值。
示例如:
Size visibleSize = Director::getInstance()->getVisibleSize(); Sprite* roope = Sprite::create("sprite.png"); roope->setPosition(Point(visibleSize.width / 2,visibleSize.height / 2)); addChild(roope); ScaleTo* scaleTo = ScaleTo::create(5.5f,0.4f,1.0f); roope->runAction(scaleTo);
然后是ScaleBy,ScaleBy的create参数和ScaleTo的一样。
ScaleBy::create(2.8f, 0.4f, 1.0f
);
如:
Size visibleSize = Director::getInstance()->getVisibleSize(); Sprite* roope1 = Sprite::create("sprite.png"); roope1->setPosition(Point(100,visibleSize.height / 2)); roope1->setScale(2.0f);//拉伸精灵 addChild(roope1); Sprite* roope2 = Sprite::create("sprite.png"); roope2->setPosition(Point(400,visibleSize.height / 2)); roope2->setScale(2.0f);//拉伸精灵 addChild(roope2); ScaleTo* scaleTo = ScaleTo::create(3.0f,1.0f,1.0f); ScaleBy* scaleBy = ScaleBy::create(3.0f,2.0f,1.0f); roope1->runAction(scaleTo); roope2->runAction(scaleBy);
这里就可以发现两者巨大的差别。
3
闪亮登场——Blink:
float duration :动作持续时间,单位为秒。
示例如:
Size visibleSize = Director::getInstance()->getVisibleSize(); Sprite* roope = Sprite::create("sprite.png"); roope->setPosition(Point(visibleSize.width / 2,visibleSize.height / 2)); addChild(roope); Blink* blink = Blink::create(5.0f,10); roope->runAction(blink);