Skip to content

Commit 8cbb1e4

Browse files
authored
Merge pull request #92 from John-Kun/master
Fix collision generation algoithm for tile size past 16
2 parents fc923a4 + 4389098 commit 8cbb1e4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

scripts/collision_generate/collision_generate.gml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
/// @param {Real} off_y The vertical offset of the sprite on the tilemap.
77
/// @param {Real} sep_x The horizontal spacing between tiles on the tilemap.
88
/// @param {Real} sep_y The vertical spacing between tiles on the tilemap.
9-
function collision_generate(_sprite_id, _angle_data, _off_x = 0, _off_y = 0, _sep_x = 0, _sep_y = 0)
9+
/// @param {Real} row_limit Use this in case you have a row lower than tilemap size.
10+
function collision_generate(_sprite_id, _angle_data, _off_x = 0, _off_y = 0, _sep_x = 0, _sep_y = 0, _row_limit = ENGINE_TILE_SIZE)
1011
{
1112
// Initialise arrays and variables for collision data
1213
var _height_arr = array_create(ENGINE_TILE_COUNT, 0);
@@ -37,10 +38,10 @@ function collision_generate(_sprite_id, _angle_data, _off_x = 0, _off_y = 0, _se
3738

3839
// Generate collision data for each tile
3940
for (var i = 1; i < ENGINE_TILE_COUNT; i++)
40-
{
41+
{
4142
var _tile = sprite_create_from_surface
4243
(
43-
_surface, _off_x + _xcell_size * (i % ENGINE_TILE_SIZE), _off_y + _ycell_size * floor(i / ENGINE_TILE_SIZE), ENGINE_TILE_SIZE, ENGINE_TILE_SIZE, false, false, 0, 0
44+
_surface, _off_x + _xcell_size * (i % _row_limit), _off_y + _ycell_size * floor(i / _row_limit), ENGINE_TILE_SIZE, ENGINE_TILE_SIZE, false, false, 0, 0
4445
);
4546

4647
_height_arr[i] = array_create(ENGINE_TILE_SIZE);
@@ -60,7 +61,6 @@ function collision_generate(_sprite_id, _angle_data, _off_x = 0, _off_y = 0, _se
6061
}
6162
}
6263
}
63-
6464
sprite_delete(_tile);
6565
}
6666

0 commit comments

Comments
 (0)