Author Topic: Randomized Tilemaps  (Read 5320 times)

Heretic

  • Moderator
  • Posts: 305
  • Castle Runner
    • View Profile
Randomized Tilemaps
« on: September 13, 2013, 11:41:39 AM »
I noticed that in some of the tilemap .xmls there are multiple sprites listed, and as such when used in the editor they seem to be randomly chosen when placed, or placed in a certain order, etc.

My problem:
I've set up a tileset to have multiple sprites but it doesn't choose or alternate between them, it chooses only the first and repeats it every time. Comparing the XMLs I can't see anything that is different between the two other than one is 16bit and the other is 32bit.
Modify message

NekoBaron

  • Posts: 124
  • Scripting Wizard
    • View Profile
Re: Randomized Tilemaps
« Reply #1 on: September 13, 2013, 06:41:33 PM »
This is my current grass  tileset xml
Code: [Select]
<tileset level="9">
<sprite scale="16">
<texture>tilemaps/az_grass.png</texture>
<frame>0 0 32 32</frame>
</sprite>
<sprite scale="16">
<texture>tilemaps/az_grass.png</texture>
<frame>32 0 32 32</frame>
</sprite>
<sprite scale="16">
<texture>tilemaps/az_grass.png</texture>
<frame>0 32 32 32</frame>
</sprite>
<sprite scale="16">
<texture>tilemaps/az_grass.png</texture>
<frame>32 32 32 32</frame>
</sprite>

</tileset>

The  frames are 32x32 size so 4 16x16 pieces
And the sprite part is the randomly selected one, so the overall size of my grass section is 64x64


If you have 4 tiles in a row you want to random between for a tileset then your xml should be something like this.

Code: [Select]
<tileset level="9">
<sprite scale="16">
<texture>tilemaps/az_grass.png</texture>
<frame>0 0 16 16</frame>
</sprite>
<sprite scale="16">
<texture>tilemaps/az_grass.png</texture>
<frame>16 0 16 16</frame>
</sprite>
<sprite scale="16">
<texture>tilemaps/az_grass.png</texture>
<frame>32 0 16 16</frame>
</sprite>
<sprite scale="16">
<texture>tilemaps/az_grass.png</texture>
<frame>48 0 16 16</frame>
</sprite>
</tileset>

Heretic

  • Moderator
  • Posts: 305
  • Castle Runner
    • View Profile
Re: Randomized Tilemaps
« Reply #2 on: September 13, 2013, 07:10:15 PM »
Yes I have different sprites set up for each one.
Code: [Select]
<tileset level="9">
<sprite scale="32">
<texture>tilemaps/gy_ruin_tiles.png</texture>
<frame>0 0 32 32</frame>
</sprite>
<sprite scale="32">
<texture>doodads/gy_ruin_tiles.png</texture>
<frame>32 0 32 32</frame>
</sprite>
</tileset>

NekoBaron

  • Posts: 124
  • Scripting Wizard
    • View Profile
Re: Randomized Tilemaps
« Reply #3 on: September 13, 2013, 08:43:53 PM »
I tried your code on my grass and it seemed to work fine for a tileset, only thing I notice is one sprite is referencing to tilemaps folder and the 2nd one is going to the doodads folder so I can only guess 1 of em is not loading or they're identical textures.

Heretic

  • Moderator
  • Posts: 305
  • Castle Runner
    • View Profile
Re: Randomized Tilemaps
« Reply #4 on: September 14, 2013, 03:03:01 AM »
Thanks you caught it :P)