C
Corablue
Guest
For collision in my previous projects I used the old method of having a reference object (obj_wall or something similar) and checking collision against that instance. There are a lot of logistical problems with this approach in more complex rooms, the least of which being GM's editor, so I'm embedding collision into the tiles themselves.
The idea is to draw only the tile layer used for collision (layer -9999) to a surface, and then transform that surface into a sprite used for collision checks. There's a very simple bit of code to do this in theory, and here's what I have so far.
//DRAW HERE is where I'm stumped.
The layer show and hide code works fine, though if there's a more efficient way to do it than looping every single tile I'd like to know that too. What I'd really like to know, however, is the code GM uses by default to draw tiles to the screen. After I set the surface to col_surf, what am I telling GM to draw? How do I get just this drawn to the surface?
Any help is hugely appreciated. Thanks!
The idea is to draw only the tile layer used for collision (layer -9999) to a surface, and then transform that surface into a sprite used for collision checks. There's a very simple bit of code to do this in theory, and here's what I have so far.
Code:
//Hide everything except collision
var num = tile_get_count();
for (var i = 0; i < num; i++;)
{
tile_set_visible(tile_get_id(i), false);
}
tile_layer_show(-9999);
//Create surface for collision map
col_surf = surface_create(room_width, room_height);
surface_set_target(col_surf);
//DRAW HERE
surface_reset_target();
spr_col_map = sprite_create_from_surface(col_surf, 0, 0, room_width, room_height, true, false, 0, 0);
//Show everything except collision
var num = tile_get_count();
for (var i = 0; i < num; i++;)
{
tile_set_visible(tile_get_id(i), true);
}
tile_layer_hide(-9999);
The layer show and hide code works fine, though if there's a more efficient way to do it than looping every single tile I'd like to know that too. What I'd really like to know, however, is the code GM uses by default to draw tiles to the screen. After I set the surface to col_surf, what am I telling GM to draw? How do I get just this drawn to the surface?
Any help is hugely appreciated. Thanks!