Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Scene Manager Question — Gideros Forum

Scene Manager Question

QuasarCreatorQuasarCreator Member
edited June 2012 in General questions
I am currently developing my first app, however, I am having a hard time to get the scene manger to switch scenes.
So, I was wondering what this meant? This is what my error log is displaying. Did I add my scenes to the wrong group?
Also, should I use self:addChild or stage:addChild when adding buttons and images?


classes/scenemanager.lua:265: bad argument #1 to 'addChild' (Sprite expected, got table)
stack traceback:

Thankyou!!

Edit: Here is my main.lua file
stage:setOrientation(Stage.LANDSCAPE_LEFT)
 
 
local sceneManager = SceneManager.new({
	["menu"] = menu,
	["pvp_level_select"] = pvp_level_select
 
})
 
sceneManager:addEventListener("transitionBegin", 
function() print("manager - transition begin") end)
 
sceneManager:addEventListener("transitionEnd", 
function() print("manager - transition end") end)
 
 
local transition = {
	SceneManager.moveFromLeft,
	SceneManager.moveFromRight,
	SceneManager.moveFromBottom,
	SceneManager.moveFromTop,
	SceneManager.moveFromLeftWithFade,
	SceneManager.moveFromRightWithFade,
	SceneManager.moveFromBottomWithFade,
	SceneManager.moveFromTopWithFade,
	SceneManager.overFromLeft,
	SceneManager.overFromRight,
	SceneManager.overFromBottom,
	SceneManager.overFromTop,
	SceneManager.overFromLeftWithFade,
	SceneManager.overFromRightWithFade,
	SceneManager.overFromBottomWithFade,
	SceneManager.overFromTopWithFade,
	SceneManager.fade,
	SceneManager.crossFade,
	SceneManager.flip,
	SceneManager.flipWithFade,
	SceneManager.flipWithShade,
}
 
local scenes = {"menu","pvp_level_select"}
 
--adding the manager to the stage
stage:addChild(sceneManager)
 
--start the menu scene
sceneManager:changeScene("menu", 1, transition)


P.S. How do I properly add code to the my post?
I am a programming noobie, so thanks in advance for helping me out and answering my questions!

Comments

  • evsevs Member
    Hard to say without seeing any code I'm afraid.


    cheers

    evs
  • ar2rsawseenar2rsawseen Maintainer
    Hello,
    so what exactly is menu and pvp_level_select.
    They should usually be sprite inherited objects:
    menu = Class.core(Sprite)
    And code can be formated using <pre lang='lua'></pre>

    Likes: QuasarCreator

    +1 -1 (+1 / -0 )Share on Facebook
  • QuasarCreatorQuasarCreator Member
    edited June 2012
    @ar2rsawseen- Thanks for giving me that piece of code. I realized I had a lower case sprite instead of Sprite. So, I am not getting any errors anymore.

    Now, when I press the pvp button on my menu which is suppose to transition to pvp_level_select the items for the pvp_level_select file show up, however, the items from the menu are still showing. So I am wondering what I am missing?

    Here is my menu file
    menu = gideros.class(Sprite)
     
    function menu:init()
     
    local pvpButton = Button.new(Bitmap.new(Texture.new("Images/pvpguide_u.png")), 
    Bitmap.new(Texture.new("Images/pvpguide_d.png")))
    pvpButton:setPosition(50, 150)
    stage:addChild(pvpButton)
     
    	--pvp button
    	pvpButton:addEventListener("click", 
    		function()
    			local transition = transition[math.random(1, 16)]
    			sceneManager:changeScene("pvp_level_select", 1, transition , easing.outBack) 
    		end
    	)
     
    local pveButton = Button.new(Bitmap.new(Texture.new("Images/pveguide_u.png")), 
    Bitmap.new(Texture.new("Images/pveguide_d.png")))
    pveButton:setPosition(125, 150)
    stage:addChild(pveButton)
     
     
     
     
    local itemsButton = Button.new(Bitmap.new(Texture.new("Images/items_u.png")), 
    Bitmap.new(Texture.new("Images/items_d.png")))
    itemsButton:setPosition(250, 200)
    stage:addChild(itemsButton)
     
     
     
     
    local goldButton = Button.new(Bitmap.new(Texture.new("Images/goldguide_u.png")), 
    Bitmap.new(Texture.new("Images/goldguide_d.png")))
    pvpButton:setPosition(200, 150)
    stage:addChild(goldButton)
     
     
     
    local title = Bitmap.new(Texture.new("Images/title.png"))
    title:setPosition( 240, 50)
    stage:addChild(title)
     
    end
    Then here is my pvp_level_select files
    <<pre escaped='true' lang='lua'>

    pvp_level_select = gideros.class(Sprite)

    function pvp_level_select:init()

    local scrollButton1 = Button.new(Bitmap.new(Texture.new("Images/scroll10-15.png")),
    Bitmap.new(Texture.new("Images/scroll10-15.png")))
    scrollButton1:setPosition(100, 100)
    stage:addChild(scrollButton1)

    end



    Thankyou!

    I am a programming noobie, so thanks in advance for helping me out and answering my questions!
  • evsevs Member
    Hello,

    Instead of adding your images to stage you should add them to self, otherwise sceneManager will not clear them as it only removes menu (or whatever class you added) and its children from the stage.

    I also keep my event listener functions separate with a name for easy removal or they'll carry on listening in the next scene
     
    menu = Core.class(Sprite)
     
    function nextScene()
     
      local transition = transition[math.random(1, 16)]
      sceneManager:changeScene("pvp_level_select", 1, transition , easing.outBack) 
     
    end
     
    function menu:init()
     
      local pvpButton = Button.new(Bitmap.new(Texture.new("Images/pvpguide_u.png")), 
      Bitmap.new(Texture.new("Images/pvpguide_d.png")))
      pvpButton:setPosition(50, 150)
      self:addChild(pvpButton)
     
      local pveButton = Button.new(Bitmap.new(Texture.new("Images/pveguide_u.png")), 
      Bitmap.new(Texture.new("Images/pveguide_d.png")))
      pveButton:setPosition(125, 150)
      self:addChild(pveButton)
     
      local itemsButton = Button.new(Bitmap.new(Texture.new("Images/items_u.png")), 
      Bitmap.new(Texture.new("Images/items_d.png")))
      itemsButton:setPosition(250, 200)
      self:addChild(itemsButton)
     
      local goldButton = Button.new(Bitmap.new(Texture.new("Images/goldguide_u.png")), 
      Bitmap.new(Texture.new("Images/goldguide_d.png")))
      goldButton:setPosition(200, 150)
      self:addChild(goldButton)
     
      local title = Bitmap.new(Texture.new("Images/title.png"))
      title:setPosition( 240, 50)
      self:addChild(title)
     
      self:addEventListener("click" , nextScene)
      self:addEventListener("exitBegin", self.onExitBegin, self)
     
    end
     
    function menu:onExitBegin()
     
     self:removeEventListener("click" , nextScene)
     
    end
    HTH


    cheers

    evs

    Likes: QuasarCreator

    +1 -1 (+1 / -0 )Share on Facebook
  • @evs
    Thank you very much my app works perfectly now!
    I am a programming noobie, so thanks in advance for helping me out and answering my questions!
Sign In or Register to comment.