Pencil Code Reference > twist

 

twist changes the rotation of an image

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.

Syntax

anobject.twist 40

In the above example, the graphic would be rotated 40 degrees clockwise.

Twist rotates the graphic instantly and has no visual animation.

Example

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.