Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// @func fCollision_Grid_BakeLayers
- var _tileLayers = fEditor_Layer_Get_TileLayerList();
- var _grid = oLayerController.collisionGrid;
- ds_grid_clear(_grid,0);
- for (var l = 0; l < ds_list_size(_tileLayers); l++){
- var _layer = _tileLayers[| l];
- if (!fEditor_Layer_Get_IsLayerCollision(_layer)){
- continue;
- }
- var _tilemapList = fEditor_Layer_Get_ElementsOfType(_collisionLayerMap,layerelementtype_tilemap);
- for (var tm = 0; tm < ds_list_size(_tilemapList); tm++){
- var _tilemap = _tilemapList[| tm];
- var _tilemapDims = [
- tilemap_get_x(_tilemap),
- tilemap_get_y(_tilemap),
- tilemap_get_width(_tilemap),
- tilemap_get_height(_tilemap)];
- var _tilesProcessed = 0;
- var _tilesTotal = fEditor_Layer_Tilemap_NumTiles_Get(_tilemap);
- if (_tilesTotal == 0){
- continue;
- }
- if (_tilemapDims[rectWH.w] % TILE_SIZE != 0 || _tilemapDims[rectWH.h] % TILE_SIZE != 0){
- fTrace("[WARN] fCollision_Grid_BakeLayers: Tilemap offset is not divisible by tile size!");
- }
- if (_tilemapDims[rectWH.x] + _tilemapDims[rectWH.w] >= ds_grid_width(oLayerController.collisionGrid) ||
- _tilemapDims[rectWH.y] + _tilemapDims[rectWH.h] >= ds_grid_height(oLayerController.collisioNGrid)){
- fTrace("[WARN] fCollision_Grid_BakeLayers: Tilemap size exceeds collision grid size for some reason!");
- }
- var _gridOffsetX = _tilemapDims[rectWH.x];
- var _gridOffsetY = _tilemapDims[rectWH.y];
- for (var ty = 0; ty < _tilemapDims[rectWH.h]; ty++){
- if (_tilesProcessed == _tilesTotal){
- break;
- }
- for (var tx = 0; tx < _tilemapDims[rectWH.w]; tx++){
- if (_tilesProcessed == _tilesTotal){
- break;
- }
- var _cellHasTile = !tilemap_tile_empty(_tilemap,tx,ty);
- _grid[# tx + _gridOffsetX, ty + _gridOffsetY] |= _cellHasTile;
- _tilesProcessed += _cellHasTile;
- }
- }
- }
- ds_list_destroy(_tilemapList);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement