Hi,
I’m developing a simple game (my first one) which has several scenes. The first one shows a logo, and the second one shows the game menu. The game Works fine in corona simulator, android and xcode emulator, but in iOS devices it doesn’t.
The problem: After the first scene is shown, a logo image remains on top despite second scene (the menu) is executed, avoiding user can see the menu. Despite menu.lua (second scene) executes a storyboard.removeAll() the logo (shown in first scene - loadapp.lua) remains on top.
I’ve tries different approaches like removing logo images or using alpha property, but they don’t work. what am i doing wrong? any ideas? As I mentiones before this problema is only present in iOS device version.
main.lua code
–Initial Settings
display.setStatusBar( display.HiddenStatusBar ) --Hide status bar from the beginning
– Import sqlite and storyboard
local sqlite3 = require(“sqlite3”)
local storyboard = require “storyboard”
storyboard.purgeOnSceneChange = true --So it automatically purges for us
–Create a database table for holding the high scores in.
local dbPath = system.pathForFile(“gamedata.db3”, system.DocumentsDirectory)
local db = sqlite3.open( dbPath )
local tablesetup = [[
CREATE TABLE IF NOT EXISTS settings (id INTEGER PRIMARY KEY,
sound_on,
music_on,
game_rush);
INSERT INTO settings VALUES (1, ‘1’, ‘1’,‘0’ );
]]
db:exec( tablesetup ) --Create it now.
local tablescores = [[
CREATE TABLE IF NOT EXISTS scores (id INTEGER PRIMARY KEY,
score);
]]
db:exec( tablescores ) --Create it now.
db:close() --Then close the database
–Now change scene to go to the menu.
storyboard.gotoScene( “loadapp”, “fade”, 400 ) – loads first scene
loadapp.lua (first scene)
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
–controls
local backgroundImg
local menutimer
– *** STORYBOARD SCENE EVENT FUNCTIONS ***
function scene:createScene( event )
local screenGroup = self.view
backgroundImg = display.newImageRect(“images/logo.png”,480,320)
backgroundImg.x = display.contentCenterX; backgroundImg.y = display.contentCenterY
screenGroup:insert(backgroundImg)
– Cambia al MainMenu screen
local gotoMainMenu = function()
display.remove(backgroundImg)
backgroundImg = nil
storyboard.gotoScene(“menu”,“crossFade”, 400)
end
menutimer = timer.performWithDelay( 3000, gotoMainMenu, 1 ) – after 3secs displays menu scene
end
function scene:enterScene( event )
end
function scene:exitScene( event )
– cancel timer
timer.cancel( menutimer ); menutimer = nil;
end
function scene:destroyScene( event )
end
– Add the story board event listeners
scene:addEventListener( “createScene”, scene )
scene:addEventListener( “enterScene”, scene )
scene:addEventListener( “exitScene”, scene )
scene:addEventListener( “destroyScene”, scene )
menu.lua (second scene)
module(…,package.seeall)
–Start off by requiring storyboard and creating a scene.
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
- visible controls
local displayGroup = display.newGroup( )
local buttons = display.newGroup( )
local playBtn
local optionsBtn
local creditsBtn
local backgroundImg
local logo
– *** STORYBOARD SCENE EVENT FUNCTIONS ***
function scene:createScene( event )
local screenGroup = self.view
--Background image…
backgroundImg = display.newImageRect( “images/background1.png”, 480,320)
backgroundImg.x = display.contentCenterX
backgroundImg.y = display.contentCenterY
displayGroup:insert(backgroundImg)
logo = display.newImageRect( “images/logo.png”, 278 * 1.20,185 * 1.20)
logo.x = display.contentCenterX; logo.y = 115
displayGroup:insert(logo)
– Play button
local onPlayTouch = function()
local optionsscr =
{
effect = “crossFade”,
time = 400
}
storyboard.gotoScene(“game”, optionsscr)
end
playBtn = display.newImageRect(“images/playOn.png”, 90, 90 )
playBtn:setReferencePoint( display.CenterReferencePoint);
playBtn.x = display.contentCenterX
playBtn.y = 250
buttons:insert( playBtn )
playBtn:addEventListener(“touch”, function(event) onPlayTouch() end)
– Settings button
local onSettingsTouch = function()
local optionsscr =
{
effect = “crossFade”,
time = 400
}
storyboard.gotoScene(“gamesettings”, optionsscr)
end
optionsBtn = display.newImageRect(“images/settingsOn.png”, 75, 75)
optionsBtn:setReferencePoint( display.CenterReferencePoint )
optionsBtn.x = 100
optionsBtn.y = 250
buttons:insert( optionsBtn )
optionsBtn:addEventListener(“touch”, function(event) onSettingsTouch() end)
– Credits button
local onCreditsTouch = function()
local optionsscr =
{
effect = “crossFade”,
time = 400
}
storyboard.gotoScene(“gamecredits”, optionsscr)
end
creditsBtn = display.newImageRect(“images/creditsOn.png”, 75, 75)
creditsBtn:setReferencePoint( display.CenterReferencePoint )
creditsBtn.x = 380
creditsBtn.y = 250
buttons:insert( creditsBtn )
creditsBtn:addEventListener(“touch”, function(event) onCreditsTouch() end)
end
– Called immediately after scene has moved onscreen:
– Start timers/transitions etc.
function scene:enterScene( event )
local screenGroup = self.view
storyboard.removeAll( )
buttons.alpha = 1
displayGroup.alpha = 1
screenGroup:insert(displayGroup)
screenGroup:insert(buttons)
end
function scene:exitScene( event )
end
function scene:destroyScene( event )
end
– Add the story board event listeners
scene:addEventListener( “createScene”, scene )
scene:addEventListener( “enterScene”, scene )
scene:addEventListener( “exitScene”, scene )
scene:addEventListener( “destroyScene”, scene )
–Return the scene to storyboard.
return scene