Hello,
I have a question about rotations in Codea.
Is there a way not to change the x and y coordinates while rotating?
If I use for example rotate(90) it rotates the sprite, but by doing this it changes its coordinates so it is sometimes out of the screen.
I would like to rotate the sprite around its center.
I searched the forum but haven’t find an answer yet.
Thanks for answers in advance.
You need to translate to its position. For example, to draw a sprite rotated 90° you can do:
pushMatrix()
translate(WIDTH/2, HEIGHT/2)
rotate(90)
sprite("Documents:WhateverSprite", 0, 0, whateverWidth)
popMatrix()
Thanks!
That’s exactly what I wanted
@Leon just be careful because the order of operations matters
So this:
rotate(90)
translate(WIDTH/2, HEIGHT/2)
Means something different from this:
translate(WIDTH/2, HEIGHT/2)
rotate(90)
A good general rule is to read the transform operations from the bottom up, because that is the ‘order’ in which they will apply.
@Leon - I explain it here
https://coolcodea.wordpress.com/2013/05/17/53-3d-drawing-a-simple-image-part-2/
I also have some eBooks on the Index page
Thanks again
I’ll read it immediately