2015년 6월 20일 토요일

corona sdk 에서 tiled 사용하기 08 – Complex Physics Objects



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


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

08 – Complex Physics Objects (복잡한 물리 객체들)

Difficulty: Beginner
Duration: 20 minutes
Description:
In a previous tutorial we saw how easy it was to create simple physics objects from tiles and objects, we will now see how easy it is to create more interesting shapes.

Step 1: Getting your map (맵로딩)

For this tutorial we are going to use the map we created in the previous tutorial, make sure to remove any physics objects you created for the interesting bit of terrain in the centre as that is what we are going to build today.
앞예제에서 사용했던 맵을 로딩하면 됩니다.

Step 2: Creating a circular object (원형 object 생성하기)

Creating a circular body couldn’t be simpler and can be done on both tiles and objects, this example will show you how to create one on a tile however it is the same process for an object.
원형 body를 만드는것은 간단하지 않습니다. 이번 예제는 원형 타일에서 body를 만드는 예제입니다.
First set up your tile properties as before, remembering to include the “HasBody” property. Then simply add a “radius” property as shown below.
타일 속성을 HasBody를 넣고 radius를 넣으면 됩니다. 그러면 타일이 원형 body를 가지게 됩니다.
Radius Property
You can of course still set all the other physics properties as before I am just showing this now to keep it nice and simple.
You may also wish to set the DrawMode to “hybrid” just so that you can see your new circular body.
앞에서 얘기언급했지만 Map>>MapProperty 에 Physics:DrawMod hybrid를 추가하면 아래와같이 물리 충돌 영역을 볼 수 있습니다.
Circle In Game

Step 3: Creating a polygon object (다각형 object 만들기)

Circles are great for some things but what is really great is custom shapes, these can help make terrain creation so much simpler. Rather than using trial and error with rotation you can just draw out your terrain like a dot-to-dot picture.
원형도 대단하지만 다각형 툴이 진짜 대단합니다. 암튼 다각형 툴을 잘사용하면 복잡한 모형도 표현 할 수 있습니다.
In order to do this you will use the polygon tool. Click at the corners of your polygon. The resulting shape must also be convex-only, so you'll need to break up any concave shapes into several convex ones.
Multiple Shapes
I have also set the bodyType to static in the Object Properties to make sure it stays where we want it and have added some more tiles above it to see them fall and slide on our terrain.
앞에서도 설명했지만, 이렇게 만들었으면 배경은 보통 bodyType을 static으로 해야합니다.
그래야지 중력에 의해서 아래로 떨어지거나 밀리지 않습니다.

Step 4: Run your game (게임 실행하세요)

If you run your game now you will see all your tiles fall onto your new terrain.
위의 예제를 제대로 작업했다면 타일들이 아래와 같이 떨어지는것을 볼 수 있습니다.
Complete

Step 5: Even more complex shapes (심지어 좀 더 복잡한 형태)

In a soon to be created tutorial you will see how easy it is to create bodies built up of multiple shapes.
좀 더 작성될 예제에서는 얼마나 쉽게 만드는지 보여준다는데...., 기대해봐야겠네요.
Resources:
Completed Project: git clone https://github.com/anthonymoralez/lime-tutorials

꼭 알아두세요.
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 선택함
12. 물리세계 원형으로 처리하려면 프로퍼티 radius=? 추가함

댓글 없음:

댓글 쓰기