Dynamic level editor (I post here too much)

letmethink

  • *
  • Posts: 2545
I'll probably be adding some sort of lighting next so the further in the darker the tiles appear. I'll also probably write about my methods of snapping the tiles at some point.
~Letmethink

Justin

  • *
  • Posts: 4716
This is pretty cool. It's funny timing, too. I'm working right now on adding autotile support to stencyl, so you'll probably see it in an upcoming release, but it's awesome that you were able to figure it out on your own. :D
For Live Support: Join our discord server and ping me @justin.
I'm most often available between 10am and 10pm Japan time. (GMT+9)

letmethink

  • *
  • Posts: 2545
Oh cool. It's a feature I've been wanting to see for quite a while. The method I used involvesadding certain amounts based on where tiles exist:



If a tile appears at each location you add the number. Then I wrote a program using five tiles like so:



It takes the corners and arranges them in a nice 16x16 grid that I can import into stencyl:



And then I wrote an interpreter as seen in the diagram above. I have attached the program for creating the grid below;
~Letmethink

Bombini

  • *
  • Posts: 1400
Fantastic!
I used a much much simpler method and didnt like working on it at all :)

letmethink

  • *
  • Posts: 2545
What was your simpler method?
~Letmethink

Bombini

  • *
  • Posts: 1400
Simple but not better at all.
I am checking if and where are tiles on a specific layer and change/create tiles depending on what the player does (dig or whatever).

Bombini

  • *
  • Posts: 1400
I am currently reworking my diggin mechanic (not using if for a level editor but ingame).
The whole "IF" method is way to complex and CPU hungry.
May i ask what your approach is?

I read this article but i dont know where to start in Stencyl.


Justin

  • *
  • Posts: 4716
If you'd like, I can show you how to use the autotile mechanic. It's fully supported in the engine, but there's no interface for it yet so it requires working through some xml.
For Live Support: Join our discord server and ping me @justin.
I'm most often available between 10am and 10pm Japan time. (GMT+9)

Bombini

  • *
  • Posts: 1400
I would love to!
Let me know what i have to do :)

Justin

  • *
  • Posts: 4716
Quote from: Justin date=1437064042
Once I commit this, the only way to use it for those who want it ASAP, is to manually modify some XML files.

Add the following to game.xml (modifying the data if desired).

Code: [Select]
<autotileFormats>
    <format across="3" down="4" id="0" name="RMXP Autotiles">
        <autotile corners="2,4 3,4 2,5 3,5" flag="0"/>
        <autotile corners="4,0 3,4 2,5 3,5" flag="1"/>
        <autotile corners="2,4 5,0 2,5 3,5" flag="2"/>
        <autotile corners="4,0 5,0 2,5 3,5" flag="3"/>
        <autotile corners="2,4 3,4 2,5 5,1" flag="4"/>
        <autotile corners="4,0 3,4 2,5 5,1" flag="5"/>
        <autotile corners="2,4 5,0 2,5 5,1" flag="6"/>
        <autotile corners="4,0 5,0 2,5 5,1" flag="7"/>
        <autotile corners="2,4 3,4 4,1 3,5" flag="8"/>
        <autotile corners="4,0 3,4 4,1 3,5" flag="9"/>
        <autotile corners="2,4 5,0 4,1 3,5" flag="10"/>
        <autotile corners="4,0 5,0 4,1 3,5" flag="11"/>
        <autotile corners="2,4 3,4 4,1 5,1" flag="12"/>
        <autotile corners="4,0 3,4 4,1 5,1" flag="13"/>
        <autotile corners="2,4 5,0 4,1 5,1" flag="14"/>
        <autotile corners="4,0 5,0 4,1 5,1" flag="15"/>
        <autotile corners="0,4 1,4 0,5 1,5" flag="16-17,24-25"/>
        <autotile corners="0,4 5,0 0,5 1,5" flag="18-19,26-27"/>
        <autotile corners="0,4 1,4 0,5 5,1" flag="20-21,28-29"/>
        <autotile corners="0,4 5,0 0,5 5,1" flag="22-23,30-31"/>
        <autotile corners="2,2 3,2 2,3 3,3" flag="32-35"/>
        <autotile corners="2,2 3,2 2,3 5,1" flag="36-39"/>
        <autotile corners="2,2 3,2 4,1 3,3" flag="40-43"/>
        <autotile corners="2,2 3,2 4,1 5,1" flag="44-47"/>
        <autotile corners="0,2 1,2 0,3 1,3" flag="48-51,56-59"/>
        <autotile corners="0,2 1,2 0,3 5,1" flag="52-55,60-63"/>
        <autotile corners="4,4 5,4 4,5 5,5" flag="64,66,68,70"/>
        <autotile corners="4,0 5,4 4,5 5,5" flag="65,67,69,71"/>
        <autotile corners="4,4 5,4 4,1 5,5" flag="72,74,76,78"/>
        <autotile corners="4,0 5,4 4,1 5,5" flag="73,75,77,79"/>
        <autotile corners="0,4 5,4 0,5 5,5" flag="80-95"/>
        <autotile corners="4,2 5,2 4,3 5,3" flag="96-103"/>
        <autotile corners="4,2 5,2 4,1 5,3" flag="104-111"/>
        <autotile corners="0,2 5,2 0,3 5,3" flag="112-127"/>
        <autotile corners="2,6 3,6 2,7 3,7" flag="128,132,136,140"/>
        <autotile corners="4,0 3,6 2,7 3,7" flag="129,133,137,141"/>
        <autotile corners="2,6 5,0 2,7 3,7" flag="130,134,138,142"/>
        <autotile corners="4,0 5,0 2,7 3,7" flag="131,135,139,143"/>
        <autotile corners="0,6 1,6 0,7 1,7" flag="144-145,148-149,152-153,156-157"/>
        <autotile corners="0,6 5,0 0,7 1,7" flag="146-147,150-151,154-155,158-159"/>
        <autotile corners="2,2 3,2 2,7 3,7" flag="160-175"/>
        <autotile corners="0,2 1,2 0,7 1,7" flag="176-191"/>
        <autotile corners="4,6 5,6 4,7 5,7" flag="192,194,196,198,200,202,204,206"/>
        <autotile corners="4,0 5,6 4,7 5,7" flag="193,195,197,199,201,203,205,207"/>
        <autotile corners="0,6 5,6 0,7 5,7" flag="208-223"/>
        <autotile corners="4,2 5,2 4,7 5,7" flag="224-239"/>
        <autotile corners="0,2 5,2 0,7 5,7" flag="240-255"/>
    </format>
</autotileFormats>

In resources/data.xml, find any single tiles that you want to be autotiles and modify them with the following optional attributes.

autotile="0" (0 is the id of the autotile format in game.xml. If this attribute is missing, it's a standard tile)
autotileMerge="243" (243 is the id of additional tiles that this autotile can merge into)

Add an autotile image with the name [TILESET ID]-[TILE ID].png to the resources folder.

So the way the autotileFormat works is like this

Code: [Select]
<format across="3" down="4" id="0" name="RMXP Autotiles">
This means that an autotile with this format (id=0) takes its graphic from an image that's 3 tiles across and 4 tiles down (the standard RMXP Autotile image).

Code: [Select]
<autotile corners="0,2 5,2 0,7 5,7" flag="240-255"/>
This shows the four corners of the generated tile, and where they come from in the source image, counted in half-tiles.
Since we're counting in half-tiles, "0,2" is the top-left corner of the tile at 0 across, 1 down. "5,2" is the top-right corner of the tile at 3 across, 1 down. Corners are specified in the order top-left, top-right, bottom-left, bottom-right.

"Flag" specifies when the autotile should be used. It's a collection of bit flags representing the 8 neighboring tiles. You add a bit to your flag if the autotile does not connect in that direction.

Code: [Select]
CORNER_TL = 0x01; //1
CORNER_TR = 0x02; //2
CORNER_BR = 0x04; //4
CORNER_BL = 0x08; //8
SIDE_L    = 0x10; //16
SIDE_T    = 0x20; //32
SIDE_R    = 0x40; //64
SIDE_B    = 0x80; //128

So flag 240 = 128 + 64 + 32 + 16 = SIDE_B + SIDE_R + SIDE_T + SIDE_L.
This means that if a set of corners have the flag 240, those 4 corners will be used for any autotile that has different tiles to its sides, and the same tiles at its diagonals.

I've attached a test of RPG Maker style autotiles, with a fully working RMXP format, and a half-implemented RMVX format.

Since the xml autotile formats are difficult to write manually, if you specify how you want your autotile to work with example graphics, I can use a program to create it for you.
For Live Support: Join our discord server and ping me @justin.
I'm most often available between 10am and 10pm Japan time. (GMT+9)

ajimundi

  • *
  • Posts: 230
@Justin:
Wow, this is great. I was ready to chop up tiles in Gimp, and then I read this. :D

Being able to choose between VX and XP style autotiling would be wonderful. Thanks, Justin. Now all I need to figure out is to replicate the database system. Or is it coming as well? :D
::: It's never too late, unless you're dead. Maybe not even then. :::

Justin

  • *
  • Posts: 4716
For Live Support: Join our discord server and ping me @justin.
I'm most often available between 10am and 10pm Japan time. (GMT+9)

Bombini

  • *
  • Posts: 1400
Thanks a lot Justin!
It looks like its above my current level of skill but i will dig into the RPG example and try to understand.
I might get back to you but i am happy that i can remove tiles while the game is running.


« Last Edit: August 12, 2015, 12:11:49 am by Bombini »

Bombini

  • *
  • Posts: 1400
I can't get it done.
Would some one be interested in setting it up for me?
I would pay.
PM me or let me know and we can discuss

Justin

  • *
  • Posts: 4716
What part are you stuck at? I can help you figure it out (don't need money though).
For Live Support: Join our discord server and ping me @justin.
I'm most often available between 10am and 10pm Japan time. (GMT+9)