Thanks in advance for your help! Sorry about the long post.
I’m making an app that uses a popup menu to select the language (for localization).
I’m trying to create the menu as a scene (langMenuScene.lua) that covers the main scene (mainScene.lua) with a semi-transparent background and then has a view for containing the menu. I also want to ensure that the language button is not clickable when the menu is showing because it’s supposed to be obscured by the menu.
Here’s my attempt to do so:
[lua]–[[main.lua]]–
local storyboard = require “storyboard”
storyboard.gotoScene(“mainScene”)[/lua]
[lua]–[[mainScene.lua]]–
function langMenu (event)
print(“langMenu Function”)
–storyboard.loadScene(“langMenuScene”)
storyboard.gotoScene(“langMenuScene”,“slideLeft”,500)
end
function scene:createScene( event )
local group = self.view
– Show logo & header text
local r, p = 16,4 – logo radius & margin padding
local logo = display.newImageRect(“maple_leaf_small.png”, r*2, r*2) – logo image
logo.x, logo.y = r+p, r+p
local title = display.newText(strings[storyboard.settings.lang].title, r*2+p*2, p, “arial”, 20) – logo text
– create the language menu activation button (a quarter-circle in the corner of the screen, with the
– 2-character language abbreviation for its text (default: “en”)
local langButtonGroup = display.newGroup()
local langButton = display.newCircle(langButtonGroup, display.contentWidth, 0, 2*r)
local langLabel = display.newText(langButtonGroup, storyboard.settings.lang, 0, p, “arial”, 14)
langLabel.x = display.contentWidth - langLabel.width
langLabel:setTextColor(0)
langButton:addEventListener(“tap”, langMenu)
end[/lua]
[lua]–[[langMenuScene.lua]]–
function scene:createScene( event )
local group = self.view
– get width and height of display for easier calculation
local w = display.contentWidth
local h = display.contentHeight
local langGroup = display.newGroup()
– make background overlay and a view in which to put menu items
local bg = display.newRect(langGroup,0,0,w,h)
local fg = display.newRect(langGroup, w *.1 - 1, h * .1 -1, w * .8 + 2, h * .8 + 2)
– color and add transparency to menu overlay and view
bg:setFillColor(32,200)
fg:setFillColor(64,200)
– ===== Problem Spot ===== –
– I’ve tried using each of the following lines (separately):
group:insert(group) – Right: button obscured and not clickable. Wrong: error to console; no transition
group.parent:insert(group) – Right: button obscured; no error. Wrong: no transition; button clickable
group:insert(langGroup) – Right: transition; no error. Wrong: button not obscured; button clickable
end[/lua]
The “Problem Spot” at the end of the last piece of code is where I’ve been focusing my attention (after refactoring my code in other areas - like moving the language button and the logo from main.lua to mainScene.lua (it’s own scene) to prevent it showing on all scenes.
The problem is that none of the methods I’ve tried meet all of the following conditions:
- slide-transition into place
- cover/obscure the mainScene, including logo, logo text and language menu button
- make mainScene buttons unclickable (while mainScene is obscured), and
- keep the console free of errors
The error that I’ve been getting when using “group:insert(group)” is [text]…\langMenuScene.lua:20: Attempt to insert display object into itself.[/text], as I would expect it to be. And in the other two attempts, the button remains clickable (which I can tell by the “print” statement in my click function (“langMenu”)).
Can anyone please help me figure this out?
Thank you! [import]uid: 200441 topic_id: 33490 reply_id: 333490[/import]