MRDANEEYUL

sprite_create_from_tiles()

Oct 21st, 2020 (edited)
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sprite_create_from_tiles() {
  2.     var _w = sprite_width;
  3.     var _h = sprite_height;
  4.     if (_w == 0 || _h == 0) return;
  5.    
  6.     var _cliffTopZ = z + height;
  7.     var _spriteHeight = _h + height;
  8.     var _surface = surface_create(_w, _spriteHeight);
  9.  
  10.     #region Draw tiles to surface to create sprite
  11.     surface_set_target(_surface);
  12.     {      
  13.         draw_clear_alpha(c_black, 0);      
  14.         var _layers = layer_get_all();
  15.         for (var i = array_length(_layers) - 1; i >= 0; i--)
  16.         {
  17.             if (!layer_get_visible(_layers[i]) || layer_get_name(_layers[i]) == "Whitebox_Day" || layer_get_name(_layers[i]) == "Tiles_Day")
  18.                 continue;
  19.            
  20.             var _tilemapID = layer_tilemap_get_id(_layers[i]);
  21.             if (layer_get_element_type(_tilemapID) == layerelementtype_tilemap)
  22.                 draw_tilemap(_tilemapID, -x, -y);
  23.         }
  24.        
  25.         gpu_set_blendmode(bm_subtract);
  26.             draw_rectangle(TILE_SIZE/4, TILE_SIZE + 2, _w - TILE_SIZE/4, _h + height, false);
  27.             draw_rectangle(0, _h + height - TILE_SIZE, _w, _h + height, false);
  28.         gpu_set_blendmode(bm_normal);
  29.     }
  30.     surface_reset_target();
  31.     #endregion Draw tiles to surface to create sprite
  32.    
  33.     #region Create sprite and create collider/bbox
  34.     var _sprite = sprite_create_from_surface(_surface, 0, 0, _w, _spriteHeight, false, false, 0, 0);
  35.     sprite_collision_mask(_sprite, false, bboxmode_manual, 0, _cliffTopZ, _w, _h + height, bboxkind_rectangular, 0);
  36.     #endregion Create sprite and create collider/bbox
  37.        
  38.     sprite_index = _sprite;
  39.     image_xscale = 1;
  40.     image_yscale = 1;
  41.    
  42.     surface_free(_surface);
  43. }
Add Comment
Please, Sign In to add comment