Manipulating sprites
A Sprite is a 2D image that can be animated or transformed by changing its properties, including its rotation, position, scale, color, and so on. After creating a sprite you can obtain access to the variety of properties it has, which can be manipulated.
How to do it...
Rotate
You can change the sprite's rotation to positive or negative degrees.
sprite->setRotation(30.0f);
You can get the rotation value using getRotation
method.
float rotation = sprite->getRotation();
The positive value rotates it clockwise, and the negative value rotates it counter clockwise. The default value is zero. The preceding code rotates the sprite 30 degrees clockwise, as shown in the following screenshot:
Scale
You can change the sprite's scale. The default value is 1.0f
, the original size. The following code will scale to half size.
sprite->setScale(0.5f);
You can also change the width and height separately. The following code will scale to half the width only.
sprite->setScaleX(0...