2015년 6월 20일 토요일

corona sdk 에서 tiled 사용하기 07 – Making Objects Physical


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


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

07 – Making Objects Physical (물리 object 만들기)

Difficulty: Beginner
Duration: 20 minutes
Description:
In a previous tutorial we saw how easy it was to add physics to our tiles which was great for a lot of things however it would be horribly inefficient to creat our whole world out of hundreds of small physical objects. To resolve this we will instead use an Objects width and height properties to create large physical blocks that we can draw over our visual world.

Step 1: Getting your map (맵가져오기)

이건 설명이 필요없을것 같습니다. 기존에 작업하던거 가져와도 되고 없으면 여기 링크에보시면 작업된 맵이 있습니다. 다운로드 하여 사용하면 됩니다.
To make things simpler we are going to use the same map that we created in the first physics tutorial as well as knowledge we learnt in the object tutorial, so if you havent already done that these tutorials please do them now.
If you run this map now you will remember that we have a simple tile falling due to gravity and that it doesn’t get stopped by any platforms. We will now fix this.

Step 2: Creating your platform object(플랫폼 객체 생성하기)

Just like in the object tutorial we now need to create an object, only this time we are going to also set its width and height. You can do this two ways, first by manually setting the values in the Property window and secondly by actually resizing the object with your mouse.
Set Size
Try to position it over the first platform in our map such as this:
앞예제에서 한것처럼 객체 레이어를 만들어서 마우스나 프로퍼티 속성을 이용해서 크기를 설정합니다.
In Editor

Step 3: Giving it some properties (속성 설정하기)

To make your object physical you will again need to give it some properties but you will also need to set its Type to Body:
물리 속성을 주기위해서는 type을 Body로 세팅해야 합니다.
Body Type
Running your game now you will not really notice anything different, this is because that although your platform object is indeed in game and physical it is also falling due to gravity, to fix this just set its bodyType property like this:
그리고 bodyType의 static을 추가합니다. static을 넣지 않으면 중력에 의해서 아래로 떨어집니다.
화면에 보이게한뒤 물리 설정을 해야합니다.
local visual = lime.createVisual(map)
local physical = lime.buildPhysical(map)
Body Property

Step 4: Run your game (게임을 실행시키세요)

If you run your game now you will see that your tile falls and then gloriously comes to rest right on top of your platform, you may need to adjust your tiles bounce property to allow it to come to rest nicely.
제대로 만들었으면 타일 속성이 떨어져서 static으로 되어있는 곳에 멈추게 됩니다.
In Game
Feel free to create physical objects for the rest of the platforms and remember that if you create some more of those red tiles you will have loads of falling tiles.

Step 5: Setting up the physical world (물리 세계를 세팅하기)

Sometimes you or your level designer may want some more control over how the physical world is set up for a specific level, luckily this is nice and simple thanks to properties. This time we will add some new properties to our map itself, to do this select Map >> Map Properties….
좀 더 쉽게 디버깅 하기 위해서 Map>>Map Properties로 프로퍼티를 넣으면 특수한 설정을 할 수 있습니다. 아래 예제에 debug,hybrid가 있습니다.
또한 아래 설명에서 좀 더 다양한 속성을 찾을수 있습니다.
Following are all the properties that you can set:
  • Physics:GravityX Sets the magnitude of gravity along the X axis.
  • Physics:GravityY Sets the magnitude of gravity along the Y axis.
  • Physics:Scale Sets the internal pixels-per-meter ratio that is used in converting between onscreen Corona coordinates and simulated physics coordinates from the Corona API .
  • Physics:DrawMode Sets the draw mode of the physics world, can be normal, debug or hybrid.
  • Physics:PositionIterations Sets the accuracy of the engine’s position calculations from the Corona API .
  • Physics:VelocityIterations Sets the accuracy of the engine’s velocity calculations from the Corona API .
Hybrid Draw Mode
Debug Draw Mode

Step 6: A note about ramps(경사로에 대한 주의 사항)

Some of you will have noticed that not everything in nature is a flat structure and that we actually have ramps of all gradients. This can still be achieved in your game through Lime however due to a missing feature in Tiled it can be a bit fiddly, to do it simply add a rotation property to your physical objects that correspond to your visual ramps.
자연은 평평하지는 않기 때문에 경사로 작업이 귀찮은 작업입니다.rotation 프로퍼티가 있으니 사용해보세요.~~~
The tricky part is that due to Tiled not being able to rotate objects you will have to use a bit of trial and error to get your objects in the right position and rotation. This is obviously annoying and I am currently looking into ways of improving this.
까다로운 객체는 회전할수 없어서 힘들다고 하네요. 시행착오를 많이 해야 한다고 합니다.
Resources:
Completed Project: git clone https://github.com/anthonymoralez/lime-tutorials
Tileset: Download

꼭 알아두세요.
1. lime은 프로젝트 최상위 폴더에 lime폴더 통째로 복사해서 넣습니다.
2. Layer는 높은쪽이 위쪽 레이어입니다.
3. Tiled에서 tileset의 프로퍼티는 이름과 값으로 구성됩니다.
4. 화면에 보이게한뒤 물리 설정을 해야합니다. local visual = lime.createVisual(map) => local physical = lime.buildPhysical(map)
5. 타일셋에 물리 객체는 HasBody로 합니다.
6. 타일셋 import/export로 현재 저장된 프로퍼티를 다른 맵파일(tmx)과 쉽게 공유할 수 있습니다.
7. 타일을 간단하게 애니메이션 시키는 방법,IsAnimated, frameCount=?,frameTime 이 있지만 오류 발생합니다. 사용 하려면 코드 수정해야 합니다.
8. 타일 에니메이션 또다른 방법은 IsAnimated tile.sprite:setSequence("animation1") 이걸 이용하세요
9. PlayerSpawn 만들기 : object layer사용 tool을 이용하여 위치 설정 Type을 PlayerSpawn 프로퍼티 playerImage=? 추가 후 코드 추가 map:addObjectListener("PlayerSpawn", onObject)
10. 물리세계를 만들려면 object layer 에 객체를 추가한뒤 type Body로 하면됩니다. 프로퍼티 bodyType=static 추가
11. 물리세계 정보를 런타임에 디버깅 Map>>Map Properties : Physics:DrawMode=hybrid?debug?normal 선택함

댓글 없음:

댓글 쓰기