2015년 6월 26일 금요일

corona sdk 에서 tiled 사용하기 19 - Using storyboard with lime


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


 README.md


NOTE: This tutorial is not copied from the original at OutlawGameTools.com. It is similar but reworked to use the new-ishstoryboard api

19 - Using storyboard with lime (스토리보드 사용)

Difficulty: Beginner
Duration: 30 minutes
Description:
This tutorial will add a start screen, a pause button to tutorial-11. We will be using the storyboard api introduced in late 2011.

Step 1: Getting the map

The map can be found here. It is the same map used in tutorial-11. This was the one that added animation to a moving character.
튜토리얼 11에서 사용한 맵을 사용할꺼며 storyboard를 이용해서 새로 만듭니다.
소스를 다운로드 해서 하면 오류가 발생하는데 <image source="tileset-platformer.png" width="192" height="544"/> 여기 경로에 있는 tileset경로가 잘못되어 있으니 참고하여 수정하시기 바랍니다.

Step 2: Making a scene

스토리 보드는 scenetemplate.lua를 복사해서 이름만 바꿔서 작성하면 쉽게 할 수 있다고 합니다. 
The primary unit of the storyboard API is the scene. The scene is a container for each scene in your application. Each scene has a view property that will be on screen when the scene is shown. The storyboard API provides functions for switching between scenes. Scenes are referenced by the sceneName. The name can either be the name of the lua module you've created, or the name you passed to storyboard.newscene.
So let's make our first scene. The Corona API docs for the storyboard API includes a template to help with implementing a scene. There is also a copy of scenetemplate.lua in this project. We'll rename that to startscreen.lua. On this line we add a simple displayObject that will be our background. At this point we have a simple blue background. That's boring.

Step 3: Switching scenes

scene를 교체하는 방법은 storyboard.gotoScene를 사용하면 됩니다.
Transitioning from one scene to the next is straight forward: use storyboard.gotoScene. The optional options parameter is allows you to pass information from one scene to the next via the params member. You can also specify transition effects like we do on this line.

Step 4: Loading lime inside a scene

The important thing to remember here is that you need to add the map visuals to the scene's group like we do here. We've renamed the main.lua from tutorial-11 to platform.lua and tweaked it to provide a module with a public funtion to load the map, visuals, and physics as we did in tutorial 11.

Step 5: Pausing the scene with an overlay

We will now add a pause button to the game scene. We want this button to display a modal message over our existing scene. As you may have guessed the storyboard API supports this usage. The storyboard.showOverlay function is similar to the gotoScene, but instead of replacing the existing scene it is overlayed on top of it. To do this we'll create a new and very simple scene.
showOverlay로 modal message를 전달하는 예제도 같이 들어있습니다.
Do this in the createScene function:
local pause = display.newImage(group, "Play_Button.png")
pause:addEventListener("tap", function(event) 
  storyboard.showOverlay("pause", { isModal = true })
end)
When the paused overlay is started we will unregister the enterFrame listener added when the map was loaded. When it is dismissed we'll re-register the listener. These operations are exposed from the platform module as public fuctionsresumeGame and pauseGame respectively. So finally do this in the overlayBegan and overlayEnded listeners:
function scene:overlayBegan( event )
  platform.pauseGame()
end

function scene:overlayEnded( event )
  platform.resumeGame()
end
That's the basics of using the storyboard API with lime.
Resources:
Completed Project: git clone https://github.com/anthonymoralez/lime-tutorials

댓글 없음:

댓글 쓰기