Game Development Reference
In-Depth Information
Shape transformation
We know how to draw shapes on the screen now and that's great. However, no matter how
many of them we draw, they all seem to go on the top-left side of the screen. This means
that we need to change the position of the shapes. This can be done with the help of a func-
tion called Shape::setPosition() . There are also functions for the
Shape::setRotation() rotation and the Shape::setScale() scale. Actually,
those functions are all part of sf::Transformable , which the Shape class derives
from. As with most things in SFML, using these functions is extremely easy and intuitive:
Don't forget to render the shape after you get it initialized. Here is the result:
Note that we are creating a rectangle, which is actually a square, with a width and height of
50 pixels. However, we are scaling it at 2:1 and thus it is rendered longer than its original
Search WWH ::




Custom Search