This process needs to be repeated any time you change the layout of your collision tiles. You don't NEED to include every possible sprite if you have some empty space in the bottom right corner of your tileset sprite like I do, but it won't hurt if you do.Ĭlick Convert and Okay on the subsequent warning message.
Enter the correct Width and Height, the correct frames per row, and then the correct number of total frames. This will bring up a window very similar to your tileset window. Open up the newly duplicated resource and then edit the sprite in the GMS2 sprite editor.Īt the top of the screen in the menu bar there is an "image" option. My tileset is called spr_wall_tiles, and this duplicate I called spr_wall_tiles_frames. Go to your sprite resources, right click on the sprite you just used as your collision tileset and duplicate it. Okay, now we are getting to the magic part. Everything else about the layout of your tileset sprite doesn't matter beyond that. That being said there is one important thing that needs to be consistent: the first tile needs to be your "solid rectangle" tile. Mine looks like this, but the layout and available tiles can be whatever you want! However, it's not a lot of work, and only has to be re-done any time you change your collision tile set.įirst things first: we need a sprite and associated tileset that we can use to draw collisions to a tile layer.
Setting up your assetsįor this precise tile solution to work, we unfortunately need to do a bit of work in the project. Next, we'll set up our assets so that we can make those angled collision tiles behave as expected. Here's the result:Īs you can see, all "populated" tiles are considered fully solid, even if the art of the tile suggests there should be an angle. If you do this, don't forget that I call movement_and_collision from WITHIN movement_and_collision, so that call will also have to be updated. I modified movement_and_collision to accept a layer name (as a string) instead of an object, and replaced each instance of "place_meeting()" with "tile_meeting()" keeping the first two arguments the same and replacing the third argument with the layer passed in. Once you've added that to your project, you can replace all place_meeting calls with that. Tile_meeting() works exactly like you would expect place_meeting to work, but instead of telling it which object to collide with, you tell it which layer has your collision tiles drawn on it. Special thanks to most of this after showing him my own sloppy take. So our first step when converting from object to tile is to write the replacement for place_meeting. it doesn't matter- can be converted from using objects to tile by simply replacing place_meeting. Because of this, the vast majority of collision system -platformer, top down, whatever. The core of ANY object based collision system, not just the one found in TDMC, is place_meeting(). Obviously, I hope to make that more simple for you.
Adding "angled" walls or walls of any shape was difficult and often relied an a TON of complicated code or some costly operations, and almost always involved a lot of "setup" overhead that was tedious to maintain in your project. Of course, there was a draw back: tiles are rectangular, and there is no changing that. Additionally it was super easy to "paint" your world collision in the room editor by using all the features available for placing tiles. They were lightning fast regardless of how large your area was or how many collidable tiles you had in your room. When GMS2 came along and we got access to proper tile-maps, tile-based collision systems became the new hotness.
But sometimes it just isn't enough to improve overall performance, or the required systems just feel too cumbersome to maintain. There are many techniques to try to improve performance, such as deactivating walls far away from the player, or combining large "chunks" of walls into a single, larger instance. But there has always been a known downside to object based systems: performance when a large number of collision objects are present in the room, especially if those objects use "precise" collision checking. Object based collision systems are great if you are hand building your rooms in the room editor, and every room is relatively small in size.