2015년 6월 26일 금요일

corona sdk 에서 tiled 사용하기 14 – Config Files


https://github.com/anthonymoralez/lime-tutorials/tree/master/tutorial-14


 README.md


NOTE: This tutorial is copied from the original at OutlawGameTools.com

14 – Config Files (컨피그 파일)

Difficulty: Intermediate
Duration: 15 minutes
Description:
This tutorial shows off how to use config files for easy object definitions.
이번꺼는 아주 간단합니다. 그런데 15분이나 걸린다고 하네요

Step 1: Creating your map

To keep things simple for this I am going back to basics and have created a map very similar to the first one.
The Map
You can download the map here.
맵은 여기있는거 그냥 가져다 쓰세요. 아니면 귀찮을겁니다.

Step 2: Creating a config file (컨피그 파일 생성)

컨피그 파일이 뭐냐면 확장자가 json이라는 파일입니다. 당신의 친구 구글 검색해보면 나온다고 하는데요. 기본적인 맵에대한 그라운드 는 아래와 같이 할 수 있다고 하고, 해당 파일이름은 json이라고 만듭니다.
이거 매번 map에다가 일일이 적어 넣던건데 파일로 만들어 둔 뒤 맵에디터에서 간단하게 컨피그 파일 이름만 적어 주면 되는겁니다.
A config file is simply a JSON file so if you don’t know what that is please have a little read up on them. Google is your friend.
We will create a very basic config file that defines our ground object for the map:
{
    "type":"Body",
    "bodyType":"static"
}
As you can see, all we are doing is using the same properties that you would normally set in Tiled. Note that as we are making our ground from an Object so we don’t use the “HasBody” property but instead set the “type” to “Body”. Save this file as “ground.json” in your Resource directory.

Step 3: Using the config file

Now load up Tiled and on the Object Layer there will be a single Object for the ground, give it a property of “configFile” and a value of “ground.json”. If you wanted to load a config file from your Documents directory then you would change the value to “documents|ground.json”.
configFile 프로퍼티를 만들고 아까 만든 파일이름을 넣어주면 됩니다. 이런건 작업시간을 줄여주려고 하는거지 딱히 쓸모는 없을것 같습니다.
Object Properties
If you ran your game now your ground object will be built, however naturally you can’t actually see anything. So to prove this all works create the following config file and save it as “redBlock.json”.
{
    "HasBody":"",
    "bounce":1.0
}
Again, all regular stuff for making a nice bouncy block. Not that exciting but it will do for now. Now hook that up to the red tile (or any tile really) just like you did with the ground object and run the game. Voila!
In Game
One useful feature of these config files are that you can now hook that config file up to any other tile and give it the same properties, for instance try hooking it up to the other red tile and see it bounce too.

Step 4: More config files

Now create the following two config files and call them “greenBlock.json” and “yellowBlock.json” respectively. I think you can guess which tiles I would like them hooked up to.
{
    "HasBody":"",
    "bounce":0.5
}
{
    "HasBody":"",
    "bounce":0
}
Running the game now you will see your objects all behave differently based on their config files. Try adding in other properties to see what happens.
Complete

Step 5: Nested config files

Another cool feature is nested config files, this allows for a basic form of inheritance. I won’t actually demo this in the game however I will explain how you can set it up and let you have fun with it.
Instead of creating each config file as before you could create a single one called “block.json” that simply defines the base block object, like so:
대단합니다. config 파일을 중첩하는 내공을 구현하다니... 굉장히 귀찮은 방법인데 아무튼 구현이 되어 있는것 같네요.
{
    "HasBody":"",
}
You could then create a “redBlock.json” config file like this:
{
    "configFile":"block.json",
    "bounce":1.0
}
See what I did there? I specified a config file from within another config file, meaning whatever you hook the “redBlock.json” file up to will also get all properties included in the “block.json” file too. I know, amazing right?
These nested config files could go on forever constantly including other files as they go down, however the one limitation of this is that you can only have one “configFile” property on an object or config file, just like you can only have one “anything” property on any table in Lua. Sucks right? It’s ok, I got you covered. Please move on to the next step :-)

Step 5: Multiple config files

From within any config file you can give it a property of “configFiles”, this allows you to specify as many files as you desire, like so:
{
    "configFiles":[ "configFile1.json", "configFile2.json", "configFile3.json" ]
}
An important thing to take away from this is also that what you are defining here is actualy a Lua table, so if you want to create fairly complex properties that you couldn’t do in Tiled then you can do in a config file, like this:
{
    "type":"racingCar",
    "waypoints":[ "waypoint1", "waypoint2", "waypoint3" ],
    "colour":[ 255, 0, 0 ],
    "otherDetails":{ "cost":200, "name":"Awesome Car" }
}

Step 6: Why would this be useful?

엄청 편하다고 하는데 복잡해져서 불편할것 같은데 암튼 편하다고 합니다.
One reason is that it allows all the things mentioned above such as reuse of config data, inheritance and defining complex objects that would be tricky to do in Tiled but other benefits are that it allows a programmer to define an object and then a designer can just use that object in Tiled without knowing, or caring, how it is all set up. It also allows a programmer to tinker with gameplay values without having to get his feet wet in Tiled.
One other cool advantage of this is that it allows you to use the dynamic assets feature of the Corona Project Manager to swap out different config files in order to test different things.
Resources:
Completed Project: git clone https://github.com/anthonymoralez/lime-tutorials
Map: Download
Tileset: Download
Ground config file: Download
Red block config file: Download
Green block config file: Download
Yellow block config file: Download

댓글 없음:

댓글 쓰기