Omnimaga
Calculator Community => TI Calculators => Axe => Topic started by: pimathbrainiac on December 12, 2013, 10:21:13 am
-
So, I have a secret project that no one else knows about and is just in an ideas phase atm. I have a problem, though. I need to be able to rotate a "room" tilemap. 16x16 of 4x4px sprites, to be precise. This means that I want, after a trigger, for the tilemap to rotate all the tiles and also rotate the actual tilemap so the former "top" becomes one of the "sides"
I know to access a tile "normally," you do this:
For(x,0,15)
For(y,0,15)
{(y*16)+x+Map}->Var
other stuffs...
End
End
but how does one rotate the tilemap?
Thanks for the help in advance!
-
If you want to rotate it by 90° turns, rotating the tilemap is quite easy: you just add a modified subroutine to acces the tiles with the x and y coordinates swapped. And if the result is mirrored, substract one of the coordinates from 15.
To rotate the sprites themselves, it may be a bit harder, but since 4*4 sprites don't take up much space, it might be best to just save the rotated sprites as well. Just add them right after the normal tiles, in the same order (so they are at a fixed offset to the normal tiles). Then, to acces the rotated sprites, just add that offset to the pointer of the normal sprite.
If you want to rotate the tilemap by a certain amount of degrees, it will be a lot more complicated, and I don't know exactely how it should be done.
-
This is the way I did it for my version of TempleRun (http://ourl.ca/18410/367354)(it's a 16x16 tilemap at L1):
clockwise:
:For(r1,0,7)
:For(r2,0,7)
:{r2*16+r1+L1}?r3
:{r1*16+15-r2+L1}?{r2*16+r1+L1}
:{15-r2*16+15-r1+L1}?{r1*16+15-r2+L1}
:{15-r1*16+r2+L1}?{15-r2*16+15-r1+L1}
:r3?{15-r1*16+r2+L1}
:End
:End
Edit: You may need to add some code to change the sprite rotation data
-
i agree that you dont really have to rotate the actual map data in place, rather just read from it differently and rotate the sprite data when its draw in accordance.
-
Ah okay, thanks.
/me will release screenies of this project soon.
-
For rotating tiles, of course, there's rotc() and rotcc(), but I would recommend preloading rotated versions of each sprite somewhere like L1 (if the spritesheet is not too large) so it's faster to draw rotated sprites. Otherwise there might be a visible speed drop when the map is rotated, as the program would have to calculate rotated sprites on-the-fly.
-
That and rotc() and rotcc() are for 8x8 sprites. Mine are 4x4.
This super-secret project is almost to a proof-of-concept release stage. Hope to post about it soon.
-
Then your only option if you don't want a significant speed drop is to store them as separate sprites and use a variable that tells you the orientation of the tilemap.
-
That's what I'm planning on doing :P
Thanks for the helpful code, guys!
(and now to dominate the world...)