// increases X and Y size by 2.0 uniformly mySprite->setScale(2.0);
// increases just X scale by 2.0 mySprite->setScaleX(2.0);
// increases just Y scale by 2.0 mySprite->setScaleY(2.0);
动作中的缩放方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// Scale uniformly by 3x over 2 seconds auto scaleBy = ScaleBy::create(2.0f, 3.0f); mySprite->runAction(scaleBy);
// Scale X by 2 and Y by 3x over 2 seconds auto scaleBy = ScaleBy::create(2.0f, 3.0f, 3.0f); mySprite->runAction(scaleBy);
// Scale to uniformly to 3x over 2 seconds auto scaleTo = ScaleTo::create(2.0f, 3.0f); mySprite->runAction(scaleTo);
// Scale X to 2 and Y to 3x over 2 seconds auto scaleTo = ScaleTo::create(2.0f, 3.0f, 3.0f); mySprite->runAction(scaleTo);
移动
1 2 3 4 5 6 7
// Move sprite to position 50,10 in 2 seconds. auto moveTo = MoveTo::create(2, Vec2(50, 10)); mySprite1->runAction(moveTo);
// Move sprite 20 points to right in 2 seconds auto moveBy = MoveBy::create(2, Vec2(20,0)); mySprite2->runAction(moveBy);
注意到每个动作都要先创建为对象再用runAction执行
可以创建一个移动序列
1 2 3 4 5 6 7 8 9 10 11 12 13
auto moveBy = MoveBy::create(2, Vec2(500, mySprite->getPositionY()));
// MoveTo - lets move the new sprite to 300 x 256 over 2 seconds // MoveTo is absolute - The sprite gets moved to 300 x 256 regardless of // where it is located now. auto moveTo = MoveTo::create(2, Vec2(300, mySprite->getPositionY()));
// Delay - create a small delay auto delay = DelayTime::create(1);
auto seq = Sequence::create(moveBy, delay, moveTo, nullptr);
mySprite->runAction(seq);
注意到cocos里面用到数组对象时总要指定最后一位为空指针
查看源码发现runAction指接收一个参数,也就是说延迟动作只能显示写一个delay对象实现
色彩混合
1 2 3 4 5 6 7 8 9
auto mySprite = Sprite::create("mysprite.png");
// Tints a node to the specified RGB values auto tintTo = TintTo::create(2.0f, 120.0f, 232.0f, 254.0f); mySprite->runAction(tintTo);
// Tints a node BY the delta of the specified RGB values. auto tintBy = TintBy::create(2.0f, 120.0f, 232.0f, 254.0f); mySprite->runAction(tintBy);