Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Why isn't Scene Manager Changing Scenes Correctly? — Gideros Forum

Why isn't Scene Manager Changing Scenes Correctly?

ljp1203ljp1203 Member
edited October 2012 in General questions
Hi all!

I'm having a issue with the Gideros Scene Manager.

Everytime I click the button that has the listener for changing scenes, it doesn't use the transition that I put down, it just transitions regulary.

Here are my files:

main.lua
sceneManager = SceneManager.new({
	["loadmain"] = loadmain,
	["login"] = login,
	["mainmenu"] = mainmenu,
	["createEvent"] = createEvent,
	["Party"] = Party,
	["Vacation"] = Vacation,
	["Other"] = Other,
	["ViewEdit"] = ViewEdit,
	["Settings"] = Settings,
	["Help"] = Help,
	["FAQ"] = FAQ,
	["About"] = About,
})
 
stage:addChild(sceneManager)
 
sceneManager:changeScene("mainmenu")
mainmenu.lua
mainmenu = gideros.class(Sprite)
function mainmenu:init()
 
 
	--Background Image
	local background = Bitmap.new(Texture.new("Images/test.png"))
	stage:addChild(background)
 
	--Create Event Button	
	local createBtn = Bitmap.new(Texture.new("Images/btn1.png"))
	local createBtn_over = Bitmap.new(Texture.new("Images/btn1_over.png"))
 
	--The Actual Button and Listener
	local button1 = Button.new(createBtn, createBtn_over)
	button1:addEventListener("click",
		function()
			sceneManager:changeScene("createEvent", 1, SceneManager.flipWithFade)
		end)
 
	--Add Button To Scene
	button1:setPosition(70, 200)
	stage:addChild(button1)	
	-------------------------------------------------------------------------------
	--Create Event Button	
	local viewBtn = Bitmap.new(Texture.new("Images/btn2.png"))
	local viewBtn_over = Bitmap.new(Texture.new("Images/btn2_over.png"))
 
	--The Actual Button and Listener
	local button2 = Button.new(viewBtn, viewBtn_over)
	button1:addEventListener("click",
		function()
			sceneManager:changeScene("ViewEdit")
		end)
 
	--Add Button To Scene
	button2:setPosition(70, 450)
	stage:addChild(button2)
	-------------------------------------------------------------------------------
	--Create Event Button	
	local settingsBtn = Bitmap.new(Texture.new("Images/btn3.png"))
	local settingsBtn_over = Bitmap.new(Texture.new("Images/btn3_over.png"))
 
	--The Actual Button and Listener
	local button3 = Button.new(settingsBtn, settingsBtn_over)
	button1:addEventListener("click",
		function()
			sceneManager:changeScene("Settings")
		end)
 
	--Add Button To Scene
	button3:setPosition(70, 700)
	stage:addChild(button3)
	-------------------------------------------------------------------------------
 
 
end
createEvent.lua
createEvent = gideros.class(Sprite)
function createEvent:init()
 
 
	--Background Image
	local background = Bitmap.new(Texture.new("Images/test.png"))
	stage:addChild(background)
 
 
end
I really need help with this, or my app won't work :)

Thanks in Advance!
-Landon
JLS
Lead Coder and Designer

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    Well from your code, there is only one place where you use transition,
    sceneManager:changeScene("createEvent", 1, SceneManager.flipWithFade)
    Are you sure you are clicking the right button?

    It's hard to run your code without images and all other files, so if you could post a project, we might be able to help you ;)
  • ScouserScouser Guru
    Accepted Answer
    Your problem @ljp1203 appears to be a COPY & PASTE problem.

    In your mainmenu.lua you set up and add 3 buttons to the stage but each time you addEventListener you are adding it to button1 only. Maybe this is where your problem lies.

    I very nearly didn't post this reply as I didn't know where to put it as you have the same post 3 (THREE) times. This community is usually very helpful but asking the same question in 3 different posts is not the usual way to get your question answered.
  • Hi @Scouser,

    Thanks for the response! Thanks for the help and I will change it when I get home.

    Also, sorry about asking the same question THREE times, I didn't mean too. I thought that my Question wasn't entered it so I guess I submitted it THREE times.

    Sorry again, and next time I will only click the button once. ;)
    JLS
    Lead Coder and Designer
  • petecpetec Member
    Accepted Answer
    As @Scouser says, the event listener is always added to button1. I find putting simple print statements such as
    print("button 1 clicked")
    in the functions I intend to be called by buttons and temporarily commenting out the screen transition code so that the scene doesn't actually change is a handy way of finding things like this when my code doesn't do what I inetnded (often!). Once I know all my buttons are working OK then I bring back in the transition code and take it from there.

    In fact, I make really heavy use of print statements to try to follow the route my code is taking when things don't go right :)
  • ljp1203ljp1203 Member
    edited October 2012
    Hi all!

    Thanks for the responses!

    @ar2rsawseen here is my project file for you to check out!

    Thanks, (don't steal my idea! :p)
    -Landon
    JLS
    Lead Coder and Designer
  • @ljp1203 are you sure you've attached the right file?
    Is it not a Gideros project and I don't even know if it would run in Gideros.
  • ljp1203ljp1203 Member
    edited October 2012
    WOOPS!

    @ar2rsawseen I attached the wrong file. I still have my CoranaSDK project because it has some things I still need. Also, @Scouser, I like the alternative name for CoronaSDK, "beer SDK"!! :))

    I've attached the correct file this time :p

    Thanks again!
    -Landon
    zip
    zip
    PlanIt.zip
    3M
    JLS
    Lead Coder and Designer
  • petecpetec Member
    Accepted Answer
    As I've mentioned before (in one of your many threads about this ;) ), you are adding the backgrounds and the buttons to the stage rather than to the scenes. If you change things like:
    stage:addChild(background)
    stage:addChild(button1)
    to
    self:addChild(background)
    self:addChild(button1)
    then it should work (it did on the bits I tried). You need to add things to the scene rather than the stage.

    Likes: ljp1203

    +1 -1 (+1 / -0 )Share on Facebook
  • evsevs Member
    Accepted Answer
    Hello @ljp1203

    as @petec said change all stage:addChild(whatever) code to self:addChild(whatever)

    except stage:addChild(sceneManager) in main.lua

    and the transitions work


    cheers

    evs
  • Hi!!

    Thanks All for the great responses!

    @petec Thanks so much for the help. I didn't know just a couple letters could change how a whole app is working. Thanks again!

    -Landon
    JLS
    Lead Coder and Designer
  • @ljp1203 You're welcome. Glad it helped. It took me a while to get my head around stage and self when I first started with Gideros and I think it's still probably only half around it!
Sign In or Register to comment.