• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Tilemaps w/ Object-based collisions

R

Rockit381

Guest
So I've been playing around with tilemaps recently, and decided to use (if I can) tilemaps for level design meanwhile keeping an object-based collision system, since most of my game is already coded with "place_meetings" and "position_meetings" w/ an object called "Solid". I've already worked a little bit with tile-based collisions (based on a few videos, especially from GMWolf), but I've noticed that my game performs slower using this system* and I don't feel like going back and changing all my collision checks. If I have to I will, but question is how can I incorporate tilemaps meanwhile keeping an object-based collision system? I've thought of making a script that checks each tile to see if there's an open space beside it, and if there is, create a "Solid" at that tile's x & y position, but I have no clue how to program this XD Could someone please walk me through how to incorporate this or possibly show me a more efficient way of doing this? Any and all help is appreciated.

*Figured out why it runs slower (It's the hardware)
 
Last edited by a moderator:
R

Rockit381

Guest
Have you ever tried grid collisions?
I believe that's what I had used when I was working w/ tilemap collisions. Most of my code was from GMWolf's tutorial

Is this or is this not grid collision? (I'm using 8x8 tiles (a few 16x8 as well), the player's mask is 8x16)

Code:
var add_h = hspd <= mspd ? 1:0; //Keeps player from bobbing horizontally
var add_v = vspd <= grav ? 1:0; //Keeps player from bobbing vertically

y += vspd;
if vspd > 0 { //downwards
    var t1 = tilemap_get_at_pixel(tilemap,bbox_left,bbox_bottom+add_v) & tile_index_mask;
    var t2 = tilemap_get_at_pixel(tilemap,bbox_right,bbox_bottom+add_v) & tile_index_mask;
  
    if (t1 != 0) || (t2 != 0) {
        y = (((bbox_bottom+add_v) & ~7)-1) - sprite_bbox_bottom;
        vspd = 0;
    }
} else { //upwards
    var t1 = tilemap_get_at_pixel(tilemap,bbox_left,bbox_top-add_v) & tile_index_mask;
    var t2 = tilemap_get_at_pixel(tilemap,bbox_right,bbox_top-add_v) & tile_index_mask;
  
    if (t1 != 0) || (t2 != 0) {
        y = ((bbox_top + 8 - add_v) & ~7) - sprite_bbox_top;
        vspd = 0;
    }
}

x += hspd;
if hspd > 0 { //right
    var t1 = tilemap_get_at_pixel(tilemap,bbox_right+add_h,bbox_top) & tile_index_mask;
    var t2 = tilemap_get_at_pixel(tilemap,bbox_right+add_h,bbox_bottom) & tile_index_mask;
  
    if (t1 != 0) || (t2 != 0) {
        x = (((bbox_right+add_h) & ~7)-1) - sprite_bbox_right;
        hspd = 0;
    }
} else { //left
    var t1 = tilemap_get_at_pixel(tilemap,bbox_left-add_h,bbox_top) & tile_index_mask;
    var t2 = tilemap_get_at_pixel(tilemap,bbox_left-add_h,bbox_bottom) & tile_index_mask;
  
    if (t1 != 0) || (t2 != 0) {
        x = ((bbox_left + 8 - add_h) & ~7) - sprite_bbox_left;
        hspd = 0;
    }
}
 
Last edited by a moderator:

Simon Gust

Member
grid-collisions are similar but are without tile maps. I don't really know how GMS2 does it but I figure tilemap collisions are a good solution as well.
 
Top