Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
SceneManager:changeScene isn't changing the scene. — Gideros Forum

SceneManager:changeScene isn't changing the scene.

HarrisonHarrison Member
edited May 2014 in General questions
I am currently trying to change scenes with scenemanager. The probem is, when i use
sceneManager:changeScene("game", 1, SceneManager.moveFromRight, easing.outBack)
(trying to change to the "game" scene)
Also in the starting scene is the starting code and this:
function StartScene:onExitBegin()
self:removeEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
end
Basically, I want a clean slate for my actual game's code.
The elements currently on the screen are still there (and the buttons are still interactive.)
This seems rather inefficient as well as potentially problematic (imagine playing a game with a menu still loaded in the background)
What am i doing incorrectly?
also i can post the full code if necessary, but i would rather not (it could confuse people due to it having 8 .lua files, some of which do not pertain to the question.) But if you need me to post it ask me i will happily do so.
Thanks!
“ The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. ” - Tom Cargill

Comments

  • talistalis Guru
    edited May 2014
    Surely need to see the full code to answer correctly.
    But let me say some things that can be the reason:

    1-If you are using the same code in scenemanager github page, be sure that your scene names are corect in the array and in the definition part.
    local sceneManager = SceneManager.new({
    	["scene1"] = Scene1,
    	["scene2"] = Scene2,
    	["scene3"] = Scene3,
    	["scene4"] = Scene4,
    })
    local scenes = {"scene1", "scene2", "scene3", "scene4"}
    2- When you are adding something (image or anything) to the scene be sure that you are adding them to the scene not to stage. Because everything that you will add to stage will be always seen and will be on screen till you will remove it. And be sure it is on Scene init function.
    function Scene1:init(t)
    	if t then
    		print("Scene1: ", t)
    	end	
     
    	self:addChild(Bitmap.new(Texture.new("gfx/scene1.jpg")))
     
    	self:addEventListener("enterBegin", self.onTransitionInBegin, self)
    	self:addEventListener("enterEnd", self.onTransitionInEnd, self)
    	self:addEventListener("exitBegin", self.onTransitionOutBegin, self)
    	self:addEventListener("exitEnd", self.onTransitionOutEnd, self)
    end
    Scene-Manager github page:
    https://github.com/gideros/Scene-Manager
  • ar2rsawseenar2rsawseen Maintainer
    My guess would be that you are adding all your elements to the stage and not to the scene, thus even changing scene, they still are there

    Always do:
    self:addChild(sprite)
    and not
    stage:addChild(sprite)
    inside your scenes ;)
  • HarrisonHarrison Member
    edited May 2014
    yep, that was it, changed from stage to self and saw immediate results.
    How would i self:addchild for the buttons however? They are managed in a seperate button.lua and not in my scene - the button code:

    function Button:init(theSpriteName, xPos, yPos, parent)
    local parent = parent or stage
    local bitmap = Bitmap.new(Texture.new(theSpriteName, true))
    local xPos, yPos = xPos or 0, yPos or 0
    self:addChild(sprite)
    self:addEventListener(... the rest of the code ...)
    self:setPosition(xPos, yPos)
    parent:addChild(self)
    end
    “ The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. ” - Tom Cargill
  • ar2rsawseenar2rsawseen Maintainer
    @Harrison no need to manage them any way.
    you simply create an instance and add it to the scene:
    local button = Button.new(imageup, imagedown)
    self:addChild(button)
    Button it self is the sprite, so everything inside button init added to self will be added to a Sprite which you add to the scene, so everything is still attached to the scene and will change with the scene ;)
  • I changed the parent to "self" to fix the buttons, in case anyone accesses this thread in the future.
    “ The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. ” - Tom Cargill
  • ar2rsawseenar2rsawseen Maintainer
    @Harrison oh sorry, this is some kind of different button class than I use
    Yes your fix should work ;)
Sign In or Register to comment.