Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sprite_create_from_tiles() {
- var _w = sprite_width;
- var _h = sprite_height;
- if (_w == 0 || _h == 0) return;
- var _cliffTopZ = z + height;
- var _spriteHeight = _h + height;
- var _surface = surface_create(_w, _spriteHeight);
- #region Draw tiles to surface to create sprite
- surface_set_target(_surface);
- {
- draw_clear_alpha(c_black, 0);
- var _layers = layer_get_all();
- for (var i = array_length(_layers) - 1; i >= 0; i--)
- {
- if (!layer_get_visible(_layers[i]) || layer_get_name(_layers[i]) == "Whitebox_Day" || layer_get_name(_layers[i]) == "Tiles_Day")
- continue;
- var _tilemapID = layer_tilemap_get_id(_layers[i]);
- if (layer_get_element_type(_tilemapID) == layerelementtype_tilemap)
- draw_tilemap(_tilemapID, -x, -y);
- }
- gpu_set_blendmode(bm_subtract);
- draw_rectangle(TILE_SIZE/4, TILE_SIZE + 2, _w - TILE_SIZE/4, _h + height, false);
- draw_rectangle(0, _h + height - TILE_SIZE, _w, _h + height, false);
- gpu_set_blendmode(bm_normal);
- }
- surface_reset_target();
- #endregion Draw tiles to surface to create sprite
- #region Create sprite and create collider/bbox
- var _sprite = sprite_create_from_surface(_surface, 0, 0, _w, _spriteHeight, false, false, 0, 0);
- sprite_collision_mask(_sprite, false, bboxmode_manual, 0, _cliffTopZ, _w, _h + height, bboxkind_rectangular, 0);
- #endregion Create sprite and create collider/bbox
- sprite_index = _sprite;
- image_xscale = 1;
- image_yscale = 1;
- surface_free(_surface);
- }
Add Comment
Please, Sign In to add comment