Director class problem

Hi, I’ve recently started using corona and I came across the director class but I think I have done something wrong affiliated with it because the simulator is displaying a black screen when there shouldn’t be one.

Here is the code:

Main.lua:

local director = require(“director”)
display.setStatusBar(display.HiddenStatusBar)
local mainGroup = display.newGroup()
local function main()
mainGroup:insert(director.directorView)
director:changeScene(“menu”)
return true
end
main()

Menu.lua:

module(…, package.seeall)

function new()

local localGroup = display.newGroup()

local background = display.newImageRect(“graphics/background.psd”, _W, _H)
background:setReferencePoint(display.CenterReferencePoint)
background.x = _W/2
background.y = _H/2

local title = display.newImageRect(“graphics/poptitle.psd”, 300, 500)
title:setReferencePoint(display.CenterReferencePoint)
title.x = _W/2
title.y = 300

local playbutton = display.newImageRect(“graphics/play_b.psd”, 200, 300)
playbutton:setReferencePoint(display.CenterReferencePoint)
playbutton.x = _W/2
playbutton.y = 375
playbutton.scene = “game”

local levelsbutton = display.newImageRect(“graphics/levels_b.psd”, 200, 300)
levelsbutton:setReferencePoint(display.CenterReferencePoint)
levelsbutton.x = _W/2
levelsbutton.y = 320
levelsbutton.scene = “levels”

function changeScene(e)
if(e.phase == “ended”) then
director:changeScene(e.target.scene)
end
end

localGroup:insert(background)
localGroup:insert(title)
localGroup:insert(playbutton)
localGroup:insert(levelsbutton)

playbutton:addEventListener(“touch”, changeScene)
levelsbutton:addEventListener(“touch”, changeScene)

return localGroup
end

The game.lua and levels.lua files are the same as I haven’t edited either of them yet:

module(…, package.seeall)

function new()

local localGroup = display.newGroup()
return localGroup
end

Any help would be appreciated, thank you!

Are you getting any errors in your console/terminal screen?

Please read this blog post, if you don’t know how to get those messages:

http://www.coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

This is what is displayed: 06/08/2013 07:47:30.679 Corona Simulator: The file sandbox for this project is located at the following folder: (/Users/paulware/Library/Application Support/Corona Simulator/POP s-F8AFB145821B75083FE5AD8E32732D8B) 06/08/2013 07:47:30.696 Corona Simulator: ----------------------------------------------- 06/08/2013 07:47:30.696 Corona Simulator: ERROR: bad argument #2 to display.newImageRect(): width expected, but got nil. 06/08/2013 07:47:30.696 Corona Simulator: ----------------------- 06/08/2013 07:47:30.696 Corona Simulator: Director ERROR: Failed to execute new( params ) function on ‘menu’. 06/08/2013 07:47:30.696 Corona Simulator: ----------------------- 06/08/2013 07:47:30.697 Corona Simulator: /Users/paulware/Desktop/POP s/menu.lua:8: attempt to index local ‘background’ (a nil value) 06/08/2013 07:47:30.697 Corona Simulator: -----------------------

corona doesnt use psd files

try saving them as png-24 files

Okay I will try it, thank you

There is still a black screen, even with the png files

its been over a year since ive used director. is there a reason your not using storyboard

also code doesnt know what _W and _H is. they may be out of scope

I got the impression that director was easier to use, clearly not! okay thank you I will add them in now

it is a bit easier but storyboard is much better and once you grasp it its not hard

I’ve declared the variables _W and _H and now I can see my background in the simulator but nothing else, should I convert the rest of the files to jpeg because that’s what the background is? I’m going to stop with director now and learn storyboard instead, thank you

as long as they are jpeg or png should be fine are you getting any other errors

I’ve tried to convert my code from director to storyboard but I think it’s gone completely wrong, I’ll post the code

MAIN.LUA: local storyboard = require “storyboard” storyboard.purgeOnSceneChange = true display.setStatusBar(display.HiddenStatusBar) _W = display.contentWidth _H = display.contentHeight storyboard.gotoScene(“menu”) MENU.LUA: local storyboard = require “storyboard” local scene = storyboard.newScene() function scene:createScene(event) local group = self.view local bg = display.newImageRect(“graphics/background.jpg”, _W, _H) bg:setReferencePoint(display.CenterReferencePoint) bg.x = _W/2 bg.y = _H/2 local title = display.newImageRect(“graphics/poptitle.png”, 300, 500) title:setReferencePoint(display.CenterReferencePoint) title.x = _W/2 title.y = 300 local playbutton = display.newImageRect(“graphics/play_b.png”, 200, 300) playbutton:setReferencePoint(display.CenterReferencePoint) playbutton.x = _W/2 playbutton.y = 375 local levelsbutton = display.newImageRect(“graphics/levels_b.png”, 200, 300) levelsbutton:setReferencePoint(display.CenterReferencePoint) levelsbutton.x = _W/2 levelsbutton.y = 320 group:insert(bg) group:insert(title) group:insert(playbutton) group:insert(levelsbutton) playbutton:addEventListener(“touch”, changeScene) levelsbutton:addEventListener(“touch”, changeScene) end function scene:enterScene(event) local group = self.view end function scene:exitScene(event) local group = self.view end function scene:destroyScene(event) local group = self.view end scene:addEventListener(“createScene”, scene) scene:addEventListener(“enterScene”, scene) scene:addEventListener(“exitScene”, scene) scene:addEventListener(“destroyScene”, scene) return scene

I just changed all the graphics to jpg, relaunched the simulator and got an error saying “File: assertion failed!”??

double check filename spelling, case, location, extensions

Okay

they’re all fine

This is what the error says: 6/08/2013 10:58:55.394 Corona Simulator: Runtime error assertion failed! stack traceback: [C]: ? [C]: in function ‘assert’ ?: in function ‘getOrCreateTable’ ?: in function ‘addEventListener’ ?: in function ‘addEventListener’ /Users/paulware/Desktop/POP s/menu.lua:28: in function /paulware/Desktop/POP s/menu.lua:4> ?: in function ‘dispatchEvent’ ?: in function ‘gotoScene’ /Users/paulware/Desktop/POP s/main.lua:9: in main chunk

Are event listeners different in storyboard?