Legacy GM Auto tile placement, inside an object.

darijs1

Member
Im trying to save a couple of seconds of my time, by having an object which would automatically fill itself with tiles.

for example:
I would put the auto tiling object in my room, and then stretch it across where i want the tiles to fill.

I have no idea how to make such a thing, any help would be much appreciated.

Anyone got anything for this? Please point me in the right direction.
 

Phil Strahl

Member
Can you elaborate a bit, for example with a quick diagram or an example? Are you talking about, say, a section of a road or walls that you want to auto-select appropriate tiles for corners and intersection?
 

darijs1

Member
Can you elaborate a bit, for example with a quick diagram or an example? Are you talking about, say, a section of a road or walls that you want to auto-select appropriate tiles for corners and intersection?
The tile itself could be anything of my choice, but im talking about floors, and how it would be neat if i could place an object, whos xscale and yscale would be the zone which would have to be automatically filled with tiles, so i dont have to do it one by one myself. (if im not making any sense, i could try to draw something in paint)
 

Phil Strahl

Member
Ah, I think I get it; let me try to rephrase it: You want to have an object that you can scale up in the room editor and then fill the area it occupies with tiles, correct?
 

Phil Strahl

Member
Alright. In that case, I'd have an object obj_tiler holding the tile's sprite. Ideally, that sprite should have its origin on the top-left to make things easier for you. To get the amount by which you stretched an object in the editor, jsut use the built-in image_xscale and image_yscale. Now you just need to calculate how many tiles fit in there but if used the tile as a sprite, the dimensions should match, so an image_xscale of 5 would mean that 5 tiles fit across.

I can't quite recall how tile-placement in GM 1.4 worked but if possible, instead of having that object placing sprites down, it should write directly to the tile layer, but I think that got introduced with GMS 2. The point is, that you don't want to have the resulting tiles to be any different than the others.

Note, however: You won't see the effect of this in the editor, this only works at runtime. Also, you should make sure to always have your object snap to the grid programmatically so that your tiles line up. Lastly, it might not be saving you much time, as you would either need a separate object for each tile (or have an instance script that switches the tile before it runs) and then there's the issue of instance order which means that you have to make sure that those tile-fills happen in order or a big "grass" might happen after individual "house" fills, essentially overriding them.
 

darijs1

Member
Alright. In that case, I'd have an object obj_tiler holding the tile's sprite. Ideally, that sprite should have its origin on the top-left to make things easier for you. To get the amount by which you stretched an object in the editor, jsut use the built-in image_xscale and image_yscale. Now you just need to calculate how many tiles fit in there but if used the tile as a sprite, the dimensions should match, so an image_xscale of 5 would mean that 5 tiles fit across.

I can't quite recall how tile-placement in GM 1.4 worked but if possible, instead of having that object placing sprites down, it should write directly to the tile layer, but I think that got introduced with GMS 2. The point is, that you don't want to have the resulting tiles to be any different than the others.

Note, however: You won't see the effect of this in the editor, this only works at runtime. Also, you should make sure to always have your object snap to the grid programmatically so that your tiles line up. Lastly, it might not be saving you much time, as you would either need a separate object for each tile (or have an instance script that switches the tile before it runs) and then there's the issue of instance order which means that you have to make sure that those tile-fills happen in order or a big "grass" might happen after individual "house" fills, essentially overriding them.
well i made a little thing where x goes +sprite_width every step, and goes down by sprite_height when it reaches the edge...but its kinda slow to fill up....but ill take it for now.

if you can think of faster or better ways,let me know... id be grateful.
 

darijs1

Member
well i made a little thing where x goes +sprite_width every step, and goes down by sprite_height when it reaches the edge...but its kinda slow to fill up....but ill take it for now.

if you can think of faster or better ways,let me know... id be grateful.
I gave it a repeat(xscale*yscale), and it appears to be instant now. I guess this works after all.
 
Top