Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
SceneManager — Gideros Forum

SceneManager

tytadastytadas Member
edited December 2016 in General questions
Why my project works fine without any errors, but after pressing the button to go to another scene, nothing is happening.. Any ideas?

Likes: perrochon

+1 -1 (+1 / -0 )Share on Facebook
«1

Comments

  • So can you give us a little more info? You have one scene that plays okay and then it fails to transition to the next scene?
  • tytadastytadas Member
    edited December 2016
    Yes, thats right.

    Here's the code to move to another scene
    local playButton = Bitmap.new(Texture.new("images/playbutton.png", true))
    	playButton:setAnchorPoint(0.5, 0.5)
    	playButton:setPosition((conf.height - playButton:getHeight())/2 - 50, conf.width - 180)
    	self:addChild(playButton)
    	playButton:addEventListener("click", function()
    		sceneManager:changeScene("PlayScene", conf.transitionTime, conf.transition, conf.easing)
    	end)
    The most fun part everything works, so I have no idea where should I look for the error..
  • tytadastytadas Member
    edited December 2016
    Still didn't found the succesfull way to manage it out..
  • talistalis Guru
    edited December 2016
    @tytadas I have some question to you:
    1-Did you define your sceneclasses and are you sure there are really exist correspending lua files for the scenes with the same names(you should have PlayScene.lua,sc1.lua and sc2.lua for the below example) :
    sceneManager = SceneManager.new({
    	["sc1"] = sc1,
    	["sc2"] = sc2,
    	["PlayScene"] = PlayScene
     
    })
    PlayScene.lua
    PlayScene= gideros.class(Sprite)
    function PlayScene:init()
     
    	local background = Bitmap.new(Texture.new("Images/test.png"))
    	stage:addChild(background)
    --Any code actually goes here
    end
    2-After defining your sceneclasses did you added to the stage or to your own main class:
     
    stage:addChild(sceneManager)
    3-I strongly suggest you to look this code to understand better.
    http://appcodingeasy.com/Gideros-Mobile/Manage-Scenes-in-Gideros-Mobile

    Please let us know if you solve your issue.
  • @talis Thanks for the answer. Im afraid everything is just as you said..
  • can you share your project with zip file, it grasp my interest, it should work :D
    In addition can you try this one:
    https://github.com/ar2rsawseen/GameTemplate

    This is gameTemplate it also uses scene manager and it is working. So we can be sure if the problem is with your code or not.
  • Have you tried making your PlayScene just empty so it just changes the background color on init?
  • tytadastytadas Member
    edited December 2016
    I'm sorry, but I'm going to add the file codes because I already imported a lot of game stuff and images, so I would like to keep everything in a secret :D

    firstScene.lua file
    firstScene = Core.class(Sprite)
     
    function firstScene:init()
     
     
    	local bg = Bitmap.new(Texture.new("images/background.png", true))
    	bg:setAnchorPoint(0.5, 0.5)
    	bg:setPosition(conf.width/2, conf.height/2)
    	self:addChild(bg)
    	self:addEventListener("enterEnd", self.onEnterEnd, self)
     
    	local logo = Bitmap.new(Texture.new("images/logot.png", true))
    	logo:setAnchorPoint(0.5,0.5)
    	logo:setPosition((conf.height - logo:getHeight())/2 - 80, conf.width - 370)
    	self:addChild(logo)
     
    	local playButton = Bitmap.new(Texture.new("images/playbutton.png", true))
    	playButton:setAnchorPoint(0.5, 0.5)
    	playButton:setPosition((conf.height - playButton:getHeight())/2 - 50, conf.width - 180)
    	self:addChild(playButton)
    		playButton:addEventListener("click", function()
    		sceneManager:changeScene("playScene", conf.transitionTime, conf.transition, conf.easing)
    		end)
     
     
    	local settingsButton = Bitmap.new(Texture.new("images/settingsbutton.png", true))
    	settingsButton:setAnchorPoint(0.5,0.5)
    	settingsButton:setPosition((conf.height - settingsButton:getHeight())/2 - 180, conf.width - 10)
    		self:addChild(settingsButton)
     
     
    	local rateusButton = Bitmap.new(Texture.new("images/rateusbutton.png", true))
    	rateusButton:setAnchorPoint(0.5,0.5)
    	rateusButton:setPosition((conf.height - rateusButton:getWidth())/2 + 40,  conf.width - 10)
    		self:addChild(rateusButton)
     
    	local faqButton = Bitmap.new(Texture.new("images/faqbutton.png", true))
    	faqButton:setAnchorPoint(0.5,0.5)
    	faqButton:setPosition((conf.height - faqButton:getHeight())/2 - 70, conf.width + 150)
    		self:addChild(faqButton)
     
    	self:addEventListener(Event.KEY_DOWN, function(event)
    		if event.keyCode == KeyCode.BACK then
    			application:exit()
    		end
    		end)
    end
    main.lua:
    DEBUGGING = true
     
     
    PREFS = Prefe.new()
    PREFS:loadPrefs()
     
    sceneManager = SceneManager.new({
      ["Gideros"] = Gideros,
      ["LasTreasure"] = LasTreasure,
      ["firstScene"]  = firstScene,
      ["playScene"] = playScene,
    })
     
    stage:addChild(sceneManager)
     
    sceneManager:changeScene(
      "Gideros", 1, SceneManager.fade, easing.linear, 
      {
        userData = {
          onComplete = function() 
            sceneManager:changeScene(
              "LasTreasure", 1, SceneManager.fade, easing.linear, 
              {
                userData = {
                  onComplete = function() 
                    sceneManager:changeScene(
                      "firstScene", 1, SceneManager.fade, easing.linear)
                  end
                }
              })
          end
        }
      })
    I have scenemanager.lua and easing.lua aswell. my configuration.lua looks like this:
    conf = {
     
    transition = SceneManager.fade,
    transitionTime = 1,
    easing = easing.outBack,
    width = application:getContentWidth(),
    height = application:getContentHeight(),
    dx = application:getLogicalTranslateX()/application:getLogicalScaleX(),
    dy = application:getLogicalTranslateY()/application:getLogicalScaleY(),
     
    }
    And inside playScene.lua theres nothing else but just a black background.
    It seems I added everything to know about the project. I tried adding EnterEnd listener, but still doesn't seem to work.
  • But ofcourse if needed, I will share it via zip file. Just let me know! Thanks!
  • tytadastytadas Member
    edited December 2016
    @antix No, I haven't. I'm going to try it out

    Likes: antix

    +1 -1 (+1 / -0 )Share on Facebook
  • @antix It seems like it doesn't work with the background colors..
  • talistalis Guru
    edited December 2016
    @tytadas did you download the game template and tried that; Is it working?
  • Yes, it works, my other projects works aswell
  • talistalis Guru
    edited December 2016
    Lua files are not always processed in order. Maybe your configuration.lua file is executed after you need it.
    So can you add all your configration file code to init.lua.
    init.lua is some special file which Gideros will always execute first. Even before main.lua.

    Best way is to download some working Scenemanager project or create so much simple one by your self without any details (no conf file, no extra code )as i wrote before. So you can be sure if there is some problem with your code, structure etc etc....
    If it will also not work we can focus on the correct side of the problem. Now we are just wildly guessing :D
  • The most interesting part is that I widely checked mines project code dependency and the GameTemplate code dependency. There aren't any big difference or should I say the call order is the same as GameTemplate.

    GameTemplate code dependency:
    This is from the bottom to the top:
    main.lua
    start.lua
    and scenes(pack_select.lua and etc...)
    later it goes conf.lua
    and after that all the classes( dataSaver, scenemanager..)

    Mine code dependency:
    main.lua
    firstScene.lua
    2 splashscreen scenes
    configuration.lua
    and classes

    So the call order is the same type as the GameTemplate. I checked the call order already for like 150 times, It can't be true that I'm missing something, ofcourse it's possible but I'm a human as everyone else. Sorry for your time
  • I created fast and simple scenemanager project:

    main.lua:
    sceneManager = SceneManager.new({
    ["start"] = start,
    ["play"] = play
    })
    stage:addChild(sceneManager)
     
    sceneManager:changeScene("start", 1, SceneManager.moveFromRight, easing.outBack)
    start:
    start = Core.class(Sprite)
     
    function start:init()
    local background = Bitmap.new(Texture.new("12223.jpg"))
    self:addChild(background)
     
    background:addEventListener("click", function()
    	sceneManager:changeScene("play", 1, SceneManager.fade, easing.outBack)
     
    end)
    end
    play.lua:
    play = Core.class(Sprite)
     
    function play:init()
     
    	local texturee = TextField.new(nil, "I am here")
    	texture:setPosition(100,100)
    	self:addChild(texture)
     
    end
    Doesn't work while pressing on a background.. but the background is small, on the corner
  • I'm definately missing something..
  • talistalis Guru
    edited December 2016 Accepted Answer
    In your event listener did you define custom event "click" ? Just use Event.Mouse_DOWN which is already defined maybe
    Try like this please:
    main.lua
    sceneManager = SceneManager.new({
    ["start"] = start,
    ["play"] = play
    })
    stage:addChild(sceneManager)
     
    sceneManager:changeScene("start", 1, SceneManager.moveFromRight, easing.outBack)
    start.lua
    start = Core.class(Sprite)
     
    function start:init()
     
    	local texture2 = TextField.new(nil, "Click ME")
    	texture2:setPosition(100,100)
    	self:addChild(texture2)
     
     
    texture2:addEventListener(Event.MOUSE_DOWN, function()
    	sceneManager:changeScene("play", 1, SceneManager.fade, easing.outBack)
     
    end)
    end
    play.lua
    play = Core.class(Sprite)
     
    function play:init()
     
    	local texturee = TextField.new(nil, "I am here")
    	texturee:setPosition(100,100)
    	self:addChild(texturee)
     
    end
    Please copy paste all above and tell us the result , curious about it.

    Likes: tytadas

    +1 -1 (+1 / -0 )Share on Facebook
  • Yea it works. But I can't understand whats the mistake, the "click" worked on my first project.. o.O
  • So it seems there is something wrong in your PlayScene. Maybe just make a new project and copy that scene into it. Then in main just create a new instance of the PlayScene and see if Gideros Studio throws an error.

    Likes: tytadas

    +1 -1 (+1 / -0 )Share on Facebook
  • tytadastytadas Member
    edited December 2016
    @talis Hey man, You have changed my code so the button would manage the game to move to another scene. But every button now reacts to the same changeScene code, I have 4 buttons, and all the 4 buttons changes me to the "play" scene and it shouldn't be like that.. What to do?? :(
  • What should I do now?
  • @tytadas, if you make a new blank scene and start that instead of your play scene does it work or not work?
  • yes, it works. But imagine you have 4 different buttons, and all the buttons,while being pressed and the scene changes right? And my codes on different buttons has different change scene name:
    changeScene("gamesc" 1..)
     
                               changeScene("settsc", 1..)
    But both buttons directs to the gamesc, while there is settsc scene.
  • hgy29hgy29 Maintainer
    edited December 2016
    @tytadas, I am late in the discussion but reading earlier posts I assume your button event listener is something like:
    texture2:addEventListener(Event.MOUSE_DOWN, function()
    	sceneManager:changeScene("play", 1, SceneManager.fade, easing.outBack)
    end)
    which would work if there is only one such button in the scene, because if you have more than one, you need to check that click coordinates are within your button bounds. That is :
    texture2:addEventListener(Event.MOUSE_DOWN, function(e)
     if texture2:hitTestPoint(e.x,e.y,true) then
      sceneManager:changeScene("play", 1, SceneManager.fade, easing.outBack)
     end
    end)
    Or something similar. If my assumptions are correct and doing this fixes your issue, I'll leave it to as an exercise to explain to others why you had such a behaviour without that check :P
  • I'm sooo.. I forgot about hitTestPoint -_- Thanks @hgy29, but I'm afraid it does not work as it should,
    Output:
    attempt to index global 'e' (a nil value)
    Line 3 executes an error, which is:
    if texture2:hitTestPoint(e.x,e.y,true) then
  • edited December 2016
    Another way to debug project like this is to make code clean and using a class if possible.
    Can you try using the button class from here:
    https://github.com/gideros/Button/blob/master/button.lua

    I think @hgy29 assumptions is correct and Button Class will help you with hitTestPoint error above.
    Coming soon
  • hgy29hgy29 Maintainer
    @tytadas, thre is something weird because 'e' variable (event) isn't global in this scope, it is the function argument (or you missed it maybe) ?
  • @hgy29 No, I just copied your code and it looks like this(this is mainsc.lua):
    function mainsc:onEnterEnd()
     
     
    	local playbutton = Bitmap.new(Texture.new("images/playbutton.png", true))
    	playbutton:setPosition((conf.height - playbutton:getHeight())/2 - 50, conf.width - 180)
    	playbutton:setAnchorPoint(0.5,0.5)
    	self:addChild(playbutton)
     
    	playbutton:addEventListener(Event.MOUSE_DOWN, function()
    		if playbutton:hitTestPoint(e.x,e.y,true) then
    		sceneManager:changeScene("gamesc", conf.transitionTime, conf.transition, conf.easing)
    		end
    		end)
     
     
     
    	local settingsButton = Bitmap.new(Texture.new("images/settingsbutton.png", true))
    	settingsButton:setAnchorPoint(0.5,0.5)
    	settingsButton:setPosition((conf.height - settingsButton:getHeight())/2 - 180, conf.width - 10)
    	self:addChild(settingsButton) 
     
    	settingsButton:addEventListener(Event.MOUSE_DOWN, function()
    		if settingsButton:hitTestPoint(e.x,e.y,true) then
    		sceneManager:changeScene("setsc", conf.transitionTime, conf.transition, conf.easing)
    		end
    		end)
    end
    main.lua:
    sceneManager = SceneManager.new({
      ["Gideros"] = Gideros,
      ["LasTreasure"] = LasTreasure,
      ["mainsc"] = mainsc,
      ["gamesc"] = gamesc,
      ["setsc"] = setsc,
     
    })
     
    stage:addChild(sceneManager)
     
    sceneManager:changeScene(
      "Gideros", 1, SceneManager.fade, conf.easing, 
      {
        userData = {
          onComplete = function() 
            sceneManager:changeScene(
              "LasTreasure", 1, SceneManager.fade, conf.easing, 
              {
                userData = {
                  onComplete = function() 
                    sceneManager:changeScene(
                      "mainsc", 1, SceneManager.fade, conf.easing)
                  end
                }
              })
          end
        }
      })
    And output shows this:
    /mainsc.lua:37: attempt to index global 'e' (a nil value)
    stack traceback:
    	scenes/mainsc.lua:37: in function <scenes/mainsc.lua:36>
    If I use "click" it does not work and buttons do not react to a touch. But now the error is different
  • @vitalitymobile I will try, but a bit later at work now
    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.