Tuesday, March 29, 2016

GameMaker: Collision with Background tiles

If you've ever checked out Shaun Spalding's GameMaker tutorial series, you'll see that he has a quick and easy way of resolving collision between the player and the wall objects. This is what I've been using for my current GameMaker projects, but a problem soon become apparent when I wanted to fill in the background with tiles.

The above features a room, with the player character terrain composed entirely of several objects, each one a black square of dimension 16x16(pixels).

This (the above) however, is what I want people to see in the game. This background is done up using a tilesheet with each tile of dimension 16x16(pixels).

Originally, I settled for a rather tedious method of first laying out the collision objects, after which I'll paint the tiles over them. The tedium soon got to me and I wonder if there is a way to automate part of this process.

This is what I eventually ended up with:

During creation of the room, I looped through all of the tiles in the room and created instances of the collision object in place of each tile. Note that the collision object (o_Wall) has been set to be invisible. The logic is about as simple as it gets. For a gml novice like myself, the bigger challenge is in reading through the documentation and finding out just what functionalities are provided.

In hindsight, it probably would have been a better idea to rewrite the collision to work with tiles instead. For now though, I'll stick to this method until performance becomes an issue.

No comments: