OZONE Asylum
Forums
Server-Side Scripting - Oh my!
Godot and Auto-Tiling WJ-style
This page's ID:
33334
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Okay. I've got the algorithm and some code to play with. But I don't know how to get it into Godot. Time to look at file formats. In particular, *.tres for the actual tile map graphic, and *.tscn files that hold the level map. The only information that I could find is that the various files are "human readable" text files. Okay. Time for my game face. Rawr! Let's take a look at a tres file: [code] [gd_resource type="TileSet" load_steps=3 format=2] [ext_resource path="res://bitmask01a.png" type="Texture" id=1] [ext_resource path="res://vector.png" type="Texture" id=2] [resource] 0/name = "bitmask01a.png 0" 0/texture = ExtResource( 1 ) 0/tex_offset = Vector2( 0, 0 ) 0/modulate = Color( 1, 1, 1, 1 ) 0/region = Rect2( 0, 0, 256, 256 ) 0/tile_mode = 1 0/autotile/bitmask_mode = 0 0/autotile/icon_coordinate = Vector2( 0, 3 ) 0/autotile/tile_size = Vector2( 64, 64 ) 0/autotile/spacing = 0 0/autotile/occluder_map = [ ] 0/autotile/navpoly_map = [ ] 0/autotile/priority_map = [ ] 0/autotile/z_index_map = [ ] 0/occluder_offset = Vector2( 0, 0 ) 0/navigation_offset = Vector2( 0, 0 ) 0/shape_offset = Vector2( 0, 0 ) 0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) 0/shape_one_way = false 0/shape_one_way_margin = 0.0 0/shapes = [ ] 0/z_index = 0 1/name = "vector.png 1" 1/texture = ExtResource( 2 ) 1/tex_offset = Vector2( 0, 0 ) 1/modulate = Color( 1, 1, 1, 1 ) 1/region = Rect2( 0, 0, 64, 64 ) 1/tile_mode = 0 1/occluder_offset = Vector2( 0, 0 ) 1/navigation_offset = Vector2( 0, 0 ) 1/shape_offset = Vector2( 0, 0 ) 1/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) 1/shape_one_way = false 1/shape_one_way_margin = 0.0 1/shapes = [ ] 1/z_index = 0 [/code] I would call that fairly readable. The first texture is bitmask01.png with id=1, and all of the various things for it are denoted with '0/' at the beginning of the line. (However, I did modify that a little bit. I took out the entry for "0/autotile/bitmask_flags". That entry is 349 chars long and I didn't feel like pulling some formatting tricks.) Time to save some simple TileMap nodes as *.tscn files and take a look at those. This time I am going to pull some formatting tricks because one line in particular gets very long in a hurry. Check it out: [code] [gd_scene load_steps=2 format=2] [ext_resource path="res://black-n-white1.tres" type="TileSet" id=1] [node name="Node2D" type="Node2D"] [node name="TileMap" type="TileMap" parent="."] tile_set = ExtResource( 1 ) cell_quadrant_size = 64 format = 1 tile_data = PoolIntArray(65537, 0, 196609, 65538, 0, 3, 65539, 0, 3, 65540, 0, 3, 65541, 0, 3, 65542, 0, 0, 65545, 0, 196609, 65546, 0, 3, 65547, 0, 3, 65548, 0, 0, 65549, 0, 196609, 65550, 0, 3, 65551, 0, 3, 65552, 0, 0, 65553, 0, 196609) [/code] Iformatted tile_data a little Pythonicky. And, believe it or not, but that is only a small chunk of the actual entry. The full line of data is 2669 chars big. For the most part, human readable. But what is up with tile_data? I would call tile_data "human readable". Heh. After playing around with formatting the numbers in different ways looking for clues, I noticed that the numbers come in sets of 3. Check this out: [code] 65537, 0, 196609 65538, 0, 3 65539, 0, 3 65540, 0, 3 65541, 0, 3 65542, 0, 0 65545, 0, 196609 65546, 0, 3 65547, 0, 3 65548, 0, 0 65549, 0, 196609 65550, 0, 3 65551, 0, 3 65552, 0, 0 65553, 0, 196609 [/code] Aha! Patterns! One of my favorite things in the world. After a few more experiments and getting very similiar results, I decided to start looking at the bits. The calulator that comes with Linux has Programming Mode with a display for bits. Let's take a look at one: [code] 65537 0000 0000 0000 0001 0000 0000 0000 0001 [/code] And a peak at another one: [code] 196609 0000 0000 0000 0011 0000 0000 0000 0001 [/code] Once I started looking at the bits, it became very apparent. Like crazy apparent. The first number is the position in the level map. The right 16 bits is the x cord, and the left 16 bits is the y cord. [code] 0000 0000 0000 0001 0000 0000 0000 0001 = (1,1) 0000 0000 0000 0001 0000 0000 0000 0010 = (2,1) 0000 0000 0000 0011 0000 0000 0000 0011 = (3,3) [/code] The second number is the index in the *.tres file. In that little sample, all 0's, so '0/' in the *.tres file (even though has id=1). The second number actually holds more data in the left most bits, but it's not time to talk about that just yet. And the third number is the indexed location in the actual tile map graphic. For example, my graphic is 256x256. The step is 64. That's 16 tiles in 4x4, or (0,0)-(3,3). The upper-left tile would be: [code] 0 0000 0000 0000 0000 0000 0000 0000 0000 = (0,0) [/code] The upper-right tile would be: [code] 3 0000 0000 0000 0000 0000 0000 0000 0011 = (3,0) [/code] And just for fun from above: [code] 196609 0000 0000 0000 0011 0000 0000 0000 0001 = (1,3) [/code] Kind of redundent to show it all again because the first and third numbers operate exactly the same way. Just roll with it. I have the algorithm. I can code it. And now I know how to get it into Godot. Instead of doing all sorts of parsing, I'm gonna go with a cut-n-paste approach. - Paint a pixel map using transparency, pure black, and pure white. - Load pixel map into Python. - Scan it using overlap. - Output data in terminal. - Cut-n-paste into *.tscn file. - Fire it up in Godot. That is the basic technique and it does work. The only problem that I had was with making the assumption that all pixels in the pixel map would be #00 or #FF. I did start using Krita over Gimp because this kind of pixel painting is so much easier in Krita. But I also doubled-up in the code with a threshold sub-routine. I can now pixel paint a map and get it into Godot. If I wanted to, with a little scaling/offset magic in the code, make my pixels 12x12 and paint as sloppy as I want. It's amazing how much I can get done when I'm not working 50+ hrs at my regular job. Next I want to talk about the tile map graphic and the number work involved - and I'm going to try to do it using all ascii. Pretty basic stuff, but I want to go over it because will be doing coding. Gotta have your numbers straight when coding.
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »
Maximum Security
OZONE
DHTML/Javascript
Server-Side Scripting - Oh my!
CSS - DOM - XHTML - XML - XSL - XSLT
Stupid Basic HTML
Visual Therapy
Photoshop
Photoshop Pong, Anyone?
***WARNING*** BIG SIG APPROACHING
Photography
3D Modelling & Rendering
Multimedia/Animation
Print Graphics
Holding Pens
Philosophy and other Silliness
Outpatient Counseling
Site reviews!
Mad Scientists' Laboratory
Getting to know the Grail