SOLVED Block object with "Auto Tiling"

WasabiHeat

Member
This is more of a logic problem than a programming problem, but I've been putting together a block building/destruction system and wanted the block's sprites to dynamically change based on where blocks (of the same type) were around it, just like how the auto tiler determines tile sprites or how block sprites work in something like Spelunky.


Making code that can check all 8 spots around a given block (oWall) is easy but knowing which sprite for the block to use is the tricky part. I'd rather not use a bloated if statement / switch statement that just covers every possible combination of blocks, at least, if there's a better option available. I'm also curious as to how I would implement all of the different sprites for the block to use. as you can see in the gif I already have an autotile spritesheet working in the editor but for the block object I was thinking of having each block sprite as a frame for a single sprite resource, and the block will pick the specific image_index it needs to display. Are there any ideas for this or maybe some gamemaker functions I could delve into that would help me with this?

(at the moment my script to check the 8 spaces around a given oWall object just has 8 booleans, each representing 1 space, that turn from false to true if another oWall object is found. I was considering using a point_in_rectangle() function to count how many blocks were around the block running the code but I don't know if that will actually serve any purpose)
 

Liquid

Member
i dont understand your problem - could you ask a question more presize?

my solution suggestion:
i would put some example blocks somewhere (unseen part of room) in roomeditor, as a kind of template ruleset.
when game runs, i would search through those example templates and adjust my new tile acording to a fitting template.
ruleset.jpg
 
I just use a big bitfield and use the numeric value as an index into an array. Messy, yes, but there's less logic involved.
That's not really messy. In fact, it's the most logical and ideal way of dealing with the problem I've found. It's a bit "magic-number-y," but I feel this use case heavily justifies it. A less messy way code-wise would be horrifically wasteful graphics-wise.

Here's a fantastic engine-agnostic tutorial I used years ago when learning to do the same thing:
 

WasabiHeat

Member
That's not really messy. In fact, it's the most logical and ideal way of dealing with the problem I've found. It's a bit "magic-number-y," but I feel this use case heavily justifies it. A less messy way code-wise would be horrifically wasteful graphics-wise.

Here's a fantastic engine-agnostic tutorial I used years ago when learning to do the same thing:
That's a scary lookin' tutorial (for me at least) but if that's an ideal way of going about it then I'll definitely take the time to figure it out, so thanks for sharing! Hopefully i'll be able to post an example of it working soon
 
That's a scary lookin' tutorial (for me at least) but if that's an ideal way of going about it then I'll definitely take the time to figure it out, so thanks for sharing! Hopefully i'll be able to post an example of it working soon
Unfortunately, autotiling is inherently a more intermediate subject. I agree it can be a bit daunting at first glance (it certainly was for me), but once you take it slow and start to grasp each individual part of the process, it becomes much easier to understand the whole.
 

WasabiHeat

Member
Unfortunately, autotiling is inherently a more intermediate subject. I agree it can be a bit daunting at first glance (it certainly was for me), but once you take it slow and start to grasp each individual part of the process, it becomes much easier to understand the whole.
Well I made a day out of figuring the whole thing out and voila! It actually worked!
some of the differences between tiles are really subtle but there's a full tileset in place there and it works just as I wanted it to. Can't thank you enough for recommending me that tutorial
 
Top