Dear all,
I am porting an existing app from Graphics 1 to 2, leaving director behind, and using Composer. I am finding some different behaviors though. Two things bug me.
First, transitioning seems to be quite different, or better, it won’t work as I expect. I have a global variable that I use, and in the main I transition to “logo”, and from “logo” to “menu”. The first transition works, the second one doesn’t, and it appears immediately.
------------------------- ------------------------- FILE GLOBALS ------------------------- local globals\_ = { -- Language lang = "en", -- Display w = display.actualContentWidth, h = display.actualContentHeight, cx = display.actualContentWidth / 2, cy = display.actualContentHeight / 2, p = 10, -- Transition fade = { effect = "crossFade", time = 1000, }, -- Navigation back = "", -- Old old = { } } return globals\_ ------------------------- ------------------------- FILE MAIN ------------------------- local vars = require("globals") local log = require("log") local composer = require("composer") display.setStatusBar(display.HiddenStatusBar) vars.lang = userDefinedLanguage or system.getPreference("ui", "language") log.log("W = " .. vars.w .. " H = " .. vars.h .. " LANG = " .. vars.lang) -- This works composer.gotoScene("logo", vars.fade) ------------------------- ------------------------- FILE LOGO ------------------------- function scene:create(event) local sceneGroup = self.view local back = display.newRect(vars.cx, vars.cy, vars.w, vars.h) back:setFillColor(0, 0, 1) local logo = display.newImageRect("images/logo.png", vars.w / 6, vars.w / 6) logo.x = vars.cx logo.y = vars.cy sceneGroup:insert(back) sceneGroup:insert(logo) vars.back = "logo" -- THIS DOES NOT WORK timer.performWithDelay(2000, function(e) composer.gotoScene("menu", vars.fade) end) end
The second one, is in the menu. I need to add some rects with texts, some buttons in essence. Since I want to animate them, I want to put them in a group, and add the group to the composer.
If I use a group, the rects/texts won’t appear. If I don’t use the group, then they appear but I can’t easily move them and animate them.
function scene:create(event) local sceneGroup = self.view local back = display.newRect(vars.cx, vars.cy, vars.w, vars.h) back:setFillColor(1, 1, 0) log.log("fade " .. log.to\_string(vars.fade)) local g = display.newGroup() local y = 0 local h = 50 local w = 100 local menu = { "One", "Two", "Three" } for k, v in ipairs(menu) do log.log("adding key " .. k .. " value " .. v) local r = display.newRect(0, y, w, h) local t = display.newText(tr.tr(v), 0, y, native.systemFont, 20) r:setFillColor(1, 0, 0) t:setFillColor(0, 0, 0) g:insert(r) -- REMOVE THIS TO DISPLAY TEXT/RECTS! g:insert(t) -- REMOVE THIS TO DISPLAY TEXT/RECTS! y = y + h + vars.p end g.x = vars.cx g.y = vars.cy sceneGroup:insert(g) end
Thanks in advance for any hints!
