• 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!

Basic Platformer player code with tiles instead of objects

boy656

Member
I need some code for basic player platformer movement, except instead of colliding with objects, he will collide with tiles. Please help. do i just replace (x, y, object) with x, y, "Tile layer")? I would really appreciate some help.
 

Rob

Member
I need some code for basic player platformer movement, except instead of colliding with objects, he will collide with tiles. Please help. do i just replace (x, y, object) with x, y, "Tile layer")? I would really appreciate some help.
Did you try the code I posted in your other thread?
 

Slyddar

Member
Try this replacement for place_meeting, but for tiles.

Code:
/// @descr place_meeting_tile(x, y, layer);
/// @arg x
/// @arg y
/// @arg layer_as_string

//checks for a place_meeting at x, y with the tile layer supplied

var xx = argument0;
var yy = argument1;
var layer_id = layer_tilemap_get_id(argument2);

//save our current position
var xpos = x;
var ypos = y;

//move to test position
x = xx;
y = yy;

//check for collision
var meeting =   tilemap_get_at_pixel(layer_id, bbox_left, bbox_top) or
                tilemap_get_at_pixel(layer_id, bbox_right, bbox_top) or
                tilemap_get_at_pixel(layer_id, bbox_left, bbox_bottom) or
                tilemap_get_at_pixel(layer_id, bbox_right, bbox_bottom) or
                tilemap_get_at_pixel(layer_id, bbox_left, y) or
                tilemap_get_at_pixel(layer_id, bbox_right, y) or
                tilemap_get_at_pixel(layer_id, x, bbox_top) or
                tilemap_get_at_pixel(layer_id, x, bbox_bottom) or
                tilemap_get_at_pixel(layer_id, x, y);

//return object to original position
x = xpos;
y = ypos;

//return collision status
if meeting return true else return false;
 
Top