KanjiCoder

FOR/OATCUBE/AUTO_TILING

Sep 12th, 2022 (edited)
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | Gaming | 0 0
  1. OatCube, you might already know this, but here is a rough sketch on how to optimize your auto tiling.
  2. Assuming you are not already doing something like this.
  3.  
  4. Key Points :
  5. 1. Sprite Sheet For All Auto Tile Sets on ONE BITMAP.
  6. 2. 4 Bit Mask to calculate touching value ( t ).
  7.  
  8. #####################################################################
  9.  
  10. //: c : Current Tile ://
  11. //:gtv: Get Tile Value ://
  12. //: t : touching value ://
  13.  
  14. var c = gtv( 0 , 0 );
  15.  
  16. const ___ = ( 0 ) ;
  17. const x_0 = ( 0 - 1 ) ;
  18. const x_1 = ( 0 + 1 ) ;
  19. const y_0 = ( 0 - 1 ) ;
  20. const y_1 = ( 0 + 1 ) ;
  21.  
  22.  
  23. //: BINARY:::[ 1 1 1 1 ]
  24. //: SYMBOLIC:[ x_0 x_1 y_0 y_1 ]
  25.  
  26.  
  27. //: +-----+
  28. //: | y_0 |
  29. //: +-----+
  30. //: +-----++-----++-----+
  31. //: | x_0 || c || x_1 |
  32. //: +-----++-----++-----+
  33. //: +-----+
  34. //: | y_1 |
  35. //: +-----+
  36.  
  37. //: Sprite Sheet, graphics patterns for all
  38. //: possible 16 touching values ( t ).
  39.  
  40. BINARY: 0000 BINARY:1111
  41. | |
  42. [ 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | ... | 15 ]
  43.  
  44. var t =( 0x00
  45. | ( ( c == gtv( x_0 , ___ ) ) << 3 )
  46. | ( ( c == gtv( x_1 , ___ ) ) << 2 )
  47. | ( ( c == gtv( ___ , y_0 ) ) << 1 )
  48. | ( ( c == gtv( ___ , y_1 ) ) << 0 )
  49. );;
  50.  
  51. /// correct_sub_tile_graphic_index === t ///
  52.  
  53. var graphic_origin_x =( t * tile_width_in_pixels );
  54. var graphic_origin_y =( tile_material_type * tile_height_in_pixels );
  55.  
  56.  
  57. Assuming your sprite sheet looks like
  58.  
  59. X cell index === Sub Tile Index
  60. Y cell index === Material Type Index
  61. G == Graphic Cell
  62.  
  63. 0 1 2 3 4 5 6 7 .... SubTileIndex
  64. +---+---+---+---+---+---+---+---+
  65. 0 | G | G | G | G | G | G | G | G |
  66. +---+---+---+---+---+---+---+---+
  67. 1 | G | G | G | G | G | G | G | G |
  68. +---+---+---+---+---+---+---+---+
  69. 2 | G | G | G | G | G | G | G | G |
  70. +---+---+---+---+---+---+---+---+
  71. 3 | G | G | G | G | G | G | G | G |
  72. +---+---+---+---+---+---+---+---+
  73. 4 | G | G | G | G | G | G | G | G |
  74. +---+---+---+---+---+---+---+---+
  75.  
  76.  
  77. #####################################################################
Tags: AutoTiling
Add Comment
Please, Sign In to add comment