Pencil Code Reference > twist
twist
allows the appearance of an object to be rotated without rotating the object. This means that, if an image is turned the wrong way, you don't have to edit the image itself; you can simply rotate it in the code!
twist
is very useful for animation.
anobject.twist 40
anobject
is the name of the object being modifiedtwist
acts like rt
and rotates the graphic clockwise the given number of degrees. To rotate it counterclockwise, simply use a negative angle. In the above example, the graphic would be rotated 40 degrees clockwise.
Twist rotates the graphic instantly and has no visual animation.
Say you wanted to use the image below in your code.
First you need to import the image into your code using wear
.
e = new Sprite
e.wear "https://i.imgur.com/nUx9V2u.png"
Although this may look right, the sprite is actually still facing upwards. If you use fd
to move the ship forward, it looks like the ship moves up, not forward. Of course, we want it to look like it moves forward.
We can do this by adding e.twist -90
after e.scale .25
.
Below is an example of before and after using twist
.
Finally, use rt 90
to rotate the ship horizontally.