It looks like you're new here. If you want to get involved, click one of these buttons!
I need to render a Sprite rotated 90 degrees to the left, however if I call the roate function before drawing the sprite all my world gets rotated. I've tried calling pushMatrix and popMatrix before and after calling rotate and drawing the sprite but I see no difference.
Do you know how to achieve this??
Thanks in advance!
background(40, 40, 50)
-- Position of our sprite
spritePos = vec2( WIDTH/2, HEIGHT/2 )
-- Do this in a push/pop matrix block
-- Translate to the position first
-- Then rotate
sprite("Tyrian Remastered:Boss D", 0, 0)
The reason you need to translate before rotating is due to the order of matrix operations.
It's a little bit unintuitive but you have to imagine the operations happening in the reverse order you set them — it's as if it rotates around the origin by 90 degrees, then translates to the sprite position (so it appears as if the sprite has rotated around its center at spritePos).
Understand! I need to make my sprite position the center of the world first and then rotate the world before drawing my sprite to finally restore the previous wolrd matrix with a popMatrix! Makes sense! Thank you so much for the help!!
Simeons covered the ground work - I'm still struggling here myself - as Simeon says this is a little unintuitive. There is a good example using mesh() in Codea - the one with the spinning gem pattern. It also includes a roptated shaded triangle fill and really demonstrates the power of the pad and Codea.
I'll post something later when I get my system running.
And what about moving object? I have about 100 mooving sprites and each I need rotate. Is this posible or not?