Game Development Reference
In-Depth Information
Final facts on sprites
Sprite has a few more things to offer. All features of Texture (smoothing and repeat-
ing) work on sprite as well. To repeat a texture, we have to change the texture rectangle
(holding the texture coordinates) as we did with a Shape. For that purpose, the same func-
tion exists in the Sprite class— Sprite::setTextureRect() .
Apart from this, Sprite::getLocalBounds() and
Sprite::getGlobalBounds() make an appearance here as well. They both calcu-
late the Axis-Aligned Bounding Box ( AABB ) of the sprite. The local bounds are local to
the sprite—they do not take into consideration the transformations. On the other hand, the
global bounds transform the sprite with the position, scale, rotation and origin, and then
capture the rectangle. As we did with the shape, these can be used for basic collision detec-
tion since FloatRect (returned by the bounds functions) has a
FloatRect::intersects() function in it.
This is it for the Sprite class. We will talk about a very important topic next—resource
management.
Search WWH ::




Custom Search