Advertisement
Segfault1
Mar 23rd, 2023
199
0
Never
This is comment for paste Array move
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// Map Array Storage where Map is your 2d Array
  2.  
  3.  
  4. // define the size of each tile
  5. var tile_size = 32;
  6.  
  7. // define the number of rows and columns in the map
  8. var num_rows = array_height_2d(map);
  9. var num_cols = array_length_2d(map, 0);
  10.  
  11. // define the offset of the currently visible row
  12. var row_offset = 0;
  13.  
  14. // define the number of visible rows
  15. var num_visible_rows = room_height div tile_size;
  16.  
  17. // draw the visible portion of the map
  18. for (var row = row_offset; row < row_offset + num_visible_rows; row++) {
  19.     for (var col = 0; col < num_cols; col++) {
  20.         var tile = map[row, col];
  21.         draw_sprite(tile_sprite, tile, col*tile_size, (row-row_offset)*tile_size);
  22.     }
  23. }
  24.  
  25. // increment the row offset when scrolling down
  26. if (keyboard_check_pressed(vk_down)) {
  27.     row_offset += 1;
  28. }
  29.  
  30. // decrement the row offset when scrolling up
  31. if (keyboard_check_pressed(vk_up)) {
  32.     row_offset -= 1;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement