Author Topic: Support Request - How Does One Rotate a Tilemap?  (Read 4120 times)

0 Members and 1 Guest are viewing this topic.

Offline pimathbrainiac

  • Occasionally I make projects
  • Members
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1731
  • Rating: +136/-23
  • dagaem
    • View Profile
Support Request - How Does One Rotate a Tilemap?
« 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!
I am Bach.

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Support Request - How Does One Rotate a Tilemap?
« Reply #1 on: December 12, 2013, 12:04:32 pm »
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.
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline MGOS

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +95/-0
    • View Profile
Re: Support Request - How Does One Rotate a Tilemap?
« Reply #2 on: December 12, 2013, 12:16:45 pm »
This is the way I did it for my version of TempleRun (it's a 16x16 tilemap at L1):

clockwise:
Code: [Select]
: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
« Last Edit: December 12, 2013, 12:19:37 pm by MGOS »

Offline tr1p1ea

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 647
  • Rating: +110/-0
    • View Profile
Re: Support Request - How Does One Rotate a Tilemap?
« Reply #3 on: December 12, 2013, 06:43:26 pm »
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.
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."


Offline pimathbrainiac

  • Occasionally I make projects
  • Members
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1731
  • Rating: +136/-23
  • dagaem
    • View Profile
Re: Support Request - How Does One Rotate a Tilemap?
« Reply #4 on: December 12, 2013, 07:14:12 pm »
Ah okay, thanks.

* pimathbrainiac will release screenies of this project soon.
I am Bach.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Support Request - How Does One Rotate a Tilemap?
« Reply #5 on: December 17, 2013, 09:55:01 pm »
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.
« Last Edit: December 17, 2013, 09:55:24 pm by Deep Thought »




Offline pimathbrainiac

  • Occasionally I make projects
  • Members
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1731
  • Rating: +136/-23
  • dagaem
    • View Profile
Re: Support Request - How Does One Rotate a Tilemap?
« Reply #6 on: December 18, 2013, 07:24:45 am »
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.
I am Bach.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: Support Request - How Does One Rotate a Tilemap?
« Reply #7 on: December 18, 2013, 08:02:44 am »
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.

Offline pimathbrainiac

  • Occasionally I make projects
  • Members
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1731
  • Rating: +136/-23
  • dagaem
    • View Profile
Re: Support Request - How Does One Rotate a Tilemap?
« Reply #8 on: December 18, 2013, 08:03:50 am »
That's what I'm planning on doing :P

Thanks for the helpful code, guys!

(and now to dominate the world...)
I am Bach.