Hello,
I am planning to switch all Kwik projects from Director class to the new Storyboard API. Unfortunately I couldn’t have time to go deep into the new API and I was wondering if someone else have already made this transition, and is willing to share a few tips.
Here how Kwik works currently:
Main.lua
local director = require("director")
-- Create a main group
local mainGroup = display.newGroup()
local initPage = 1
-- Main function
local function main()
mainGroup:insert(director.directorView)
director:changeScene( "page\_"..initPage )
return true
end
main()
page_1.lua
module(..., package.seeall)
imgDir = ""
audioDir = ""
function new()
local numPages = 1
local menuGroup = display.newGroup()
local curPage = 1
local drawScreen = function()
local Firearea
Firearea = display.newImageRect( imgDir.. "p1\_firearea.png", 1024, 768 );
Firearea.x = 512; Firearea.y = 384; Firearea.alpha = 1
menuGroup:insert(Firearea)
menuGroup.Firearea = Firearea
local function flip (event)
if event.phase =="ended" then
if event.xStart \< event.x and (event.x - event.xStart) \>= 30 then
if (curPage \> 1) then
director:changeScene( "page\_"..curPage-1, "moveFromLeft" )
end
elseif event.xStart \> event.x and (event.xStart-event.x) \>= 30 then
if (curPage \< numPages) then
director:changeScene("page\_"..curPage+1, "moveFromRight")
end
end
end
end
Firearea:addEventListener("touch", flip)
end
drawScreen()
return menuGroup
end
As you can see, basically Director appears here only as repository (menuGroup) and to move between scenes.
Checking the auto created code for the new e-book template, it seems a little confuse when to use or not the several functions like scene:enterScene, exitScene, destroyScene and createScene.
In Main.lua the example is simple:
local storyboard = require "storyboard"
storyboard.gotoScene( "title" )
However, in both title.lua and page1.lua there are lots of code that are far from needed (or at least they are not exposed) in Director.
Questions are:
- do I need to create all scene:functions for each page?
- what is the best way to keep all scene elements under a single group (like the menuGroup above)?
- do I really need to add the require(“storyboard”) in all pages?
- does anyone has a better or cleaner way to transition from Director to Storyboard?
Thanks a lot,
Alex
[import]uid: 4883 topic_id: 18232 reply_id: 318232[/import]