hey i have heard of director class, but is there a different code where i can transition from start game to a page i call level select? for example, in games like angry birds when you press start, it takes you to a level select page. is there a code besides director class for this? thanks!!! [import]uid: 19836 topic_id: 6445 reply_id: 306445[/import]
Why would you want something else, director class should work for this. [import]uid: 11465 topic_id: 6445 reply_id: 22309[/import]
yeah i know. but director class isn’t working for me right now…am i doing it right? i mean i have my buttons linked to somewhere but they won’t change.
[code]
module(…, package.seeall)
local localGroup
function new()
localGroup = display.newGroup()
print( “Mazi Maze” )
local button = display.newImage( “Start Game.png” )
local function buttont ( event )
if event.phase == “ended” then
director:changeScene(“LevelSelect”,“moveFromLeft”)
end
end
button:addEventListener(“tap”,buttont)
button.x = 170
button.y = 200
localGroup:insert(button)
local button = display.newImage( “How To Play.png” )
local function buttont ( event )
if event.phase == “ended” then
director:changeScene(“HowToPlay”,“moveFromLeft”)
end
end
button:addEventListener(“tap”,buttont)
button.x = 170
button.y = 300
localGroup:insert(button)
local logo = display.newImage(“MM.png”, -20, -50 )
localGroup:insert(logo)
return localGroup
end
[import]uid: 19836 topic_id: 6445 reply_id: 22338[/import]
Not too sure about this but if I recall, I had the same problem and when I changed the listener from “tap” to “touch”, everything worked fine then. Hopes this works. [import]uid: 11809 topic_id: 6445 reply_id: 22347[/import]
still no luck…could my main file by any chance be incorrect?
[code]
display.setStatusBar( display.HiddenStatusBar )
local sky = display.newImage( “Turqouise Back.png”, 0, 0 )
local director = require(“director”)
local mainGroup = display.newGroup()
local function main()
mainGroup:insert(director.directorView)
director:changeScene(“Menu”)
return true
end
main() [import]uid: 19836 topic_id: 6445 reply_id: 22353[/import]
This is what my main.lua file looks like and then loads a splash screen for 4 seconds.
– Show StatusBar
display.setStatusBar(display.DefaultStatusBar)
–Load External UI Library and Director Library
local ui = require(“ui”)
local director = require(“director”)
–Create a Main Group
local mainGroup = display.newGroup()
–Main Function
local function main()
–Add the group from director class
mainGroup:insert(director.directorView)
–Load Main Menu
director:changeScene(“loading”)
return true
end
–Start Program
main()
This is my loading.lua:(splash screen)
– Show StatusBar
display.setStatusBar(display.DefaultStatusBar)
–Load External UI Library and Director Library
local ui = require(“ui”)
local director = require(“director”)
–Create a Main Group
local mainGroup = display.newGroup()
–Main Function
local function main()
–Add the group from director class
mainGroup:insert(director.directorView)
–Load Main Menu
director:changeScene(“loading”)
return true
end
–Start Program
main()
Then it loads my mainmenu:
module(…, package.seeall)
–Needed for Director
–Director Main function
function new()
localGroup = display.newGroup()
–Load Button Click Sound
local buttonClick = audio.loadSound(“buttonClick.wav”)
– Load Background
local screenCenterX = display.viewableContentWidth / 2
local screenCenterY = display.viewableContentHeight /2
local background = display.newImageRect(“Background.png”, 320, 480)
background.x = screenCenterX; background.y = screenCenterY
localGroup:insert(background)
–Load First Trick Screen
local function firstTrick()
audio.play(buttonClick)
director:changeScene(“firstTrick”, “downFlip”)
return true
end
–Load Second Trick Screen
local function secondTrick()
audio.play(buttonClick)
director:changeScene(“secondTrick”, “downFlip”)
return true
end
–Load Third Trick Screen
local function thirdTrick()
audio.play(buttonClick)
director:changeScene(“thirdTrick”, “downFlip”)
return true
end
–Load Fourth Trick Screen
local function fourthTrick()
audio.play(buttonClick)
director:changeScene(“fourthTrick”, “downFlip”)
return true
end
–Load Fifth Trick Screen
local function fifthTrick()
audio.play(buttonClick)
director:changeScene(“fifthTrick”, “downFlip”)
return true
end
local function infoPress()
director:changeScene(“info”, “downFlip”)
end
–Show myText
local myText = display.newText(“Please Choose a Trick”,0,0,system.nativeFont,24)
myText.x = screenCenterX
myText.y = screenCenterY * .6
localGroup:insert(myText)
–Draw First Trick Button
local firstTrickButton = ui.newButton{
default = “UpButton.png”,wid=150,hei=50,
over = “DownButton.png”,wid=150,hei=50,
onRelease = firstTrick,
id = “firstButton”,
text = “Guess your Card (1)”,
size = 12,
emboss = true}
firstTrickButton.x = screenCenterX * .5
firstTrickButton.y = screenCenterY * 1.1
localGroup:insert(firstTrickButton)
–Draw Second Trick Button
local secondTrickButton = ui.newButton{
default = “UpButton.png”,wid=150,hei=50,
over = “DownButton.png”,wid=150,hei=50,
onRelease = secondTrick,
id = “secondButton”,
text = “Guess your Number (1)”,
size = 12,
emboss = true}
secondTrickButton.x = screenCenterX * .5
secondTrickButton.y = screenCenterY *1.40
localGroup:insert(secondTrickButton)
–Draw Third Trick Button
local thirdTrickButton = ui.newButton{
default = “UpButton.png”,wid=150,hei=50,
over = “DownButton.png”,wid=150,hei=50,
onRelease = thirdTrick,
id = “thirdButton”,
text = “Guess your Card (2)”,
size = 12,
emboss = true}
thirdTrickButton.x = screenCenterX * 1.5
thirdTrickButton.y = screenCenterY *1.1
localGroup:insert(thirdTrickButton)
–Draw Fourth Trick Button
local fourthTrickButton = ui.newButton{
default = “UpButton.png”,wid=150,hei=50,
over = “DownButton.png”,wid=150,hei=50,
onRelease = fourthTrick,
id = “fourthButton”,
text = “Read your Mind”,
size = 12,
emboss = true}
fourthTrickButton.x = screenCenterX
fourthTrickButton.y = screenCenterY *1.70
localGroup:insert(fourthTrickButton)
–Draw Fifth Trick Button
local fifthTrickButton = ui.newButton{
default = “UpButton.png”,wid=150,hei=50,
over = “DownButton.png”,wid=150,hei=50,
onRelease = fifthTrick,
id = “fifthButton”,
text = “Guess your Number (2)”,
size = 12,
emboss = true}
fifthTrickButton.x = screenCenterX * 1.5
fifthTrickButton.y = screenCenterY *1.40
localGroup:insert(fifthTrickButton)
–Draw Info Button
local infoButton = ui.newButton{
default = “Info.png”, wid = 38, hei = 38,
over = “Info.png”, wid=38, hei=38,
onRelease = infoPress,
id = “infoButton”,
text = “”,
size = 12,
emboss = true}
infoButton.x = screenCenterX * 2 -30
infoButton.y = screenCenterY * 2 -30
localGroup:insert(infoButton)
return localGroup
end
From there, the user can choose which trick they want and it loads the proper screen. hope this helps you out.
[import]uid: 11809 topic_id: 6445 reply_id: 22363[/import]
okay, so i need to add all that but in the way that i want it? [import]uid: 19836 topic_id: 6445 reply_id: 22366[/import]
Not really, that’s how I did it. I think your problem is that you have an object “sky” that you load in the main.lua but doesn’t get released when you load the next screen. See in my app, I just use main.lua to load external lua files and to start the app. What helped me out a lot was watching the tutorial that Ricardo(director creator) had made. I’m new to programing in lua/Corona too so I am still learning too. The link to his video is below. I hope I helped you more then confused you.
http://developer.anscamobile.com/code/director-class-10 [import]uid: 11809 topic_id: 6445 reply_id: 22373[/import]
okay its fine. yeah i watched that video but im still a little bit unsure. sorry i don’t understand what you mean by my object “sky.” that means i need to put that line of code in every lua file i make am i correct? sorry im actually very new to this stuff. i just finished reading the resources about 3 weeks ago! [import]uid: 19836 topic_id: 6445 reply_id: 22375[/import]
Sorry, I come from programming in Visual C#. Look at how I add my background:
– Load Background
local screenCenterX = display.viewableContentWidth / 2
local screenCenterY = display.viewableContentHeight /2
local background = display.newImageRect(“Background.png”, 320, 480)
background.x = screenCenterX; background.y = screenCenterY
localGroup:insert(background)
See the last line, I add it into the group so when the next scene loads, it unloads it out of memory. This way director can release all the objects for that screen at once. [import]uid: 11809 topic_id: 6445 reply_id: 22378[/import]
okay thanks i will see what i can do, and if nothing works i will get back to you. [import]uid: 19836 topic_id: 6445 reply_id: 22381[/import]
sweet i got it work!!! i found out i was leaving something out of the code lol. [import]uid: 19836 topic_id: 6445 reply_id: 22382[/import]
Glad to hear, good luck coding. [import]uid: 11809 topic_id: 6445 reply_id: 22389[/import]
thanks you too! [import]uid: 19836 topic_id: 6445 reply_id: 22392[/import]