Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Scene not cleaning up and transitioning? — Gideros Forum

Scene not cleaning up and transitioning?

bigtunacanbigtunacan Member
edited April 2016 in General questions
I have multiple scenes and up until now they have all worked correctly. With the latest scene though it doesn't clean up the scene I'm trying to exit and never gets into the destination scene.
-- This is the source scene
json = require('json')
 
LoadingScene = Core.class(Sprite)
 
local json_loaded = false
 
function LoadingScene:init()
	print("inside loading scene")
 
	local bg = Bitmap.new(Texture.new("images/bg.png"))
	bg:setAnchorPoint(0.5, 0.5);
	bg:setPosition(conf.width/2, conf.height/2)
	self:addChild(bg)
 
	-- Setup loading spinner
	local texture = Texture.new("images/spinner.png")
	local bitmaps = {}
 
	local len = 10
	for i=1, 19 do
		bitmaps[#bitmaps+1] = {(i-1)*len+1, i*len, Bitmap.new(TextureRegion.new(texture, 0, (i-1)*108, 108, 108))}
	end
 
	local mc = MovieClip.new(bitmaps)
	mc:setGotoAction(19*len, 1)
	mc:gotoAndPlay(1)
 
	mc:setPosition(conf.width/2 - 54, conf.height/2 - 54) -- TODO: Offset by image width
 
	self:addChild(mc)
 
	local aboutText = TextWrap.new("Loading", 100, "justify", 5, conf.fontMedium)
	aboutText:setTextColor(0xffff00)
	aboutText:setPosition(conf.width/2 - 50, conf.height/2 + 100)
	self:addChild(aboutText)
	-- END : Setup loading spinner
 
	local f = io.open("|R|data_files/" .. conf.current_cardset.path, "r")
	local data = f:read("*all")
	conf.data = json.decode(data)
	f:close()
	json_loaded = true
 
	-- run world
	self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
	self:addEventListener("enterEnd", self.onEnterEnd, self)	
end
 
function LoadingScene:onEnterEnd()
	if json_loaded then
		print("json was loaded")
		--mc.stop()
		sceneManager:changeScene("cards", conf.transitionTime, conf.transition, conf.easing)
	end
end
 
function LoadingScene:onEnterFrame()
 
end
-- Destination scene
 
CardsScene = Core.class(Sprite) 
 
function CardsScene:init()
	print('inside cards scene')
 
	local bg = Bitmap.new(Texture.new("images/bg.png"))
	bg:setAnchorPoint(0.5, 0.5);
	bg:setPosition(conf.width/2, conf.height/2)
	self:addChild(bg)
 
	local aboutText = TextWrap.new("This is the cards scene...", 600, "justify", 5, conf.fontSmall)
	aboutText:setTextColor(0xffff00)
	aboutText:setPosition(100, 200)
	self:addChild(aboutText)
	-- TODO: Add init logic here
 
	-- run world
	self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
end
 
function CardsScene:onEnterFrame()
    --	print('about frame entered.')
end

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited April 2016
    I think the problem is that onEnterEnd was executed before json was loaded, and that is why nothing really changes.
    Also by making json_loaded outside the class, once you set it to true, it never goes back to false.
  • @ar2rsawseen,

    Thanks. I moved it to the
    ENTER_FRAME
    event listener instead and switched it to use an an instance variable of
     json_loaded
    that gets set in init. It is working correctly now.

    Likes: antix

    +1 -1 (+1 / -0 )Share on Facebook
  • ar2rsawseenar2rsawseen Maintainer
    Moving it to ENTER_FRAME might also be bad, make sure you don't execute it multiple times ;)
  • @ar2rsawseen,

    Yep; it's only executing once.

    I added
    self.ok_to_transition = false
    in the init. Then I'm setting this to true onEnterEnd. The onEnterFrame checks for both json_loaded and ok_to_transition.
Sign In or Register to comment.