Quick Links: Gideros Home | Download Gideros | Developer Guide
SceneManager bug?!
  • Hi guys,

    So I'm almost done with a basic, top-down RPG tutorial. I wanted to add different scenes to the program with sceneManager. Easy enough, right? Well, it turns out that if I call the "play" scene from the "start" scene it is easy enough. But when I call "character" first and then have the character scene call the "play" scene, nothing displays!?

    I've tried adding a Timer to delay the call from "character" to "play" but that doesn't help. Also, the scene is called. print("playing") will print, but the image won't display.
    Here's the code for each scene. And I attach the program as well. Any help would be appreciated. Thanks.

    main.lua:

    --set up the application variables
    application:setLogicalDimensions(1200, 1920)
    application:setOrientation(Application.LANDSCAPE_LEFT)
    application:setScaleMode("letterbox")
    application:setBackgroundColor(0x140C1C)

    --define the scenes
    sceneManager = SceneManager.new({

    ["start"] = Start, --start scene
    ["character"] = Character, --character creation scene
    ["play"] = Game, --the main game
    })

    --add manager to stage
    stage:addChild(sceneManager)

    sceneManager:changeScene("start", 1, SceneManager.flipWithFade)


    Start.lua:

    Start = gideros.class(Sprite)

    function Start:init()

    local words = TextField.new(TTFont.new("fonts/Bembo-Std.ttf", 60, true), "Touch the screen to begin")
    words:setTextColor(0xF9FAFA)
    words:setPosition(20, 200)
    words:setAlpha(1)
    self:addChild(words)

    --set up the onEnterFrame and onMouseUp EventListeners
    self:addEventListener(Event.MOUSE_UP, self.onMouseUp, self)
    self:addEventListener("exitBegin", self.onExitBegin, self)
    end

    --removing event on exiting scene
    function Start:onExitBegin()
    self:removeEventListener(Event.MOUSE_UP, self.onMouseUp, self)
    end

    function Start:onMouseUp()
    sceneManager:changeScene("character", 1, SceneManager.flipWithFade)
    end


    CharCreation.lua:
    Character = gideros.class(Sprite)

    function Character:init()

    print("character created")
    sceneManager:changeScene("play", 1, SceneManager.flipWithFade)
    end


    GamePlay.lua:

    Game = gideros.class(Sprite)

    function Game:init()

    self:addChild(Bitmap.new(Texture.new("images/foreground.png", true)))
    print("playing")
    end
    RPG tutorial.zip
    241K
  • Your project is missing easing.lua
  • Try using @ar2rsawseen GameTemplate project, because your GamePlay.lua file is wrong:
    http://giderosmobile.com/forum/discussion/480/gideros-game-template/p1
  • Hi tytadas,

    Thanks for the quick response!

    Adding easing.lua and calling sceneManager with a easing variable doesn't solve the problem.

    Also, I'm not sure how my GamePlay.lua file is wrong. @ar2sawseen has level.lua which is equivalent to my GamePlay.lua and it is simply:

    level = gideros.class(Sprite)

    function level:init()

    end

    --removing event
    function level:onEnterFrame()

    end

    --removing event on exiting scene
    function level:onExitBegin()
    self:removeEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
    end


    None of his other scenes have the last onExitBegin() function. But even adding it to GamePlay.lua doesn't help.

    So we still have a problem!?
  • pie +1 -1 (+1 / -0 )
    Member Accepted Answer
    @Greywine I think it's just a matter of timing, it works for me with this change:
    when it will create character for real it would likely take some time (or a confirmation tap by the user) that should fix it without timer tricks.. :)
    Character = gideros.class(Sprite)
     
    function Character:init()
     
     
     
    Timer.delayedCall(2000, function()
    print("character created")
    sceneManager:changeScene("play", 1, SceneManager.flipWithFade)
    end)
     
    end


    edit - which is the same as
    Character = gideros.class(Sprite)
     
    function Character:init()
     
    local function create()
    print("character created")
    sceneManager:changeScene("play", 1, SceneManager.flipWithFade)
    end
     
    Timer.delayedCall(2000, function() create() end)
     
    end

    Likes: tytadas

  • @pie Thanks so much. That did it.
  • antixantix +1 -1 (+1 / -0 )
    Member Accepted Answer
    @Greywine whilst the solution @pie provided will work it is not the best option. The best option I think would be to flesh out the scene with more code. I have attached an updated code for you to examine.

    You will see that I have included in all scenes the functions that handle events such as "enterBegin", "enterEnd", "exitBegin", and "exitEnd". Even if you do not use some of these it is good to always include them so you know you have complete control.

    Some of your classes were starting things (like touch listeners) before the scene had actually transitioned in. This is to be avoided as switching scenes too quickly can confuse sceneManager, as is demonstrated by the character scene failing to transition to the game scene.

    In your character scene I just replicated some code from the start scene so it now sits there once the scene has transitioned in and waits for another touch event before proceeding to the game scene.

    In all scenes I also added "enterFrame" code :D
    RPG tutorial 7b.zip
    242K

    Likes: tytadas

    Check out my DevBlog, my GitHub, and my games Falling Animals | Breaky Wall | Exetor

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with OpenID

In this Discussion

Top Posters