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

SceneManager question

tytadastytadas Member
edited November 2016 in General questions
I'm really confused now.. My buttons aren't being displayed on the main scene. With the background everything is Ok.
Here's my main.lua:
application:setFps(opt.fps)
application:setKeepAwake(opt.keepAwake)
 
 
 
sceneManager = SceneManager.new({
	["mainsc"] = mainsc,
	["loginfb"] = loginfb,
	["tutorial"] = tutorial,
	["rate_us"] = rate_us,
	["tutorial_login"] = tutorial_login,
	["help"] = help,
	["levels"] = levels,
})
 
stage:addChild(sceneManager)
 
 
sceneManager:changeScene("mainsc", 1, SceneManager.moveFromRight, easing.outBack)
mainsc.lua:
mainsc = Core.class(Sprite)
 
 
function mainsc:init()
 
	local background = Bitmap.new(Texture.new("background/back.png"))
	self:addChild(background)
	background:setPosition((opt.width-background:getWidth())/2, (opt.height-background:getHeight())/2)
	self:addEventListener("enterEnd", self.onEnterEnd, self)
 
 
end
 
 
function mainsc:onEnterEnd()
 
 
	local startbut = Button.new(Bitmap.new(Texture.new("buttons/login.png")))
	startbut:setPosition(200, 100)
	startbut:addEventListener("click", function()
 
 
		sceneManager:changeScene("loginscene", 1,SceneManager.moveFromRight, easing.outBack) 
	end)
 
	self:addChild(startbut)
 
 
	local startbut =  Button.new(Bitmap.new(Texture.new("buttons/tutorial.png")))
	startbut:setPosition(100, 150)
	startbut:addEventListener("click", function()
 
 
		sceneManager:changeScene("tutorial", 1, SceneManager.moveFromRight, easing.outBack) 
	end)
	self:addChild(startbut)
 
	local startbut =  Button.new(Bitmap.new(Texture.new("buttons/rateus.png")))
	startbut:setPosition(60, 150)
	startbut:addEventListener("click", function()
 
 
		sceneManager:changeScene("ratee", 1, SceneManager.moveFromRight, easing.outBack) 
	end)
	self:addChild(startbut)
 
 
 
 
end

And there is option.lua file, with few lines about the fps and awake. But the point here is that if I'am keeping this line in my code:
self:addEventListener("enterEnd", self.onEnterEnd, self)
I'm getting error:
mainsc.lua:19: attempt to index global 'Button' (a nil value)
stack traceback:
	mainsc.lua:19: in function <mainsc.lua:16>
	plug/scenemanager.lua:253: in function 'dispatchEvent'
	plug/scenemanager.lua:278: in function 'changeScene'
	main.lua:20: in main chunk
Without that line the only thing is being showed on the mainsc.lua file is background.

Any Ideas whyy? :(

Comments

  • the line
    self:addEventListener("enterEnd", self.onEnterEnd, self)
    executes function mainsc:onEnterEnd()
    line 19 of mainsc.lua could be the first time it has to create a Button, which for some reason is not available or loaded.

    I can see two possible reasons:
    1) you are loading mainsc.lua before you are loading button.lua in your project (at this time there is no Button class defined yet):
    you have to right click on mainsc.lua in gideros editor and fix the call order to parse button.lua before mainsc.lua.

    2) you forgot to import Button class in your project
    right click on project root and import button.lua (https://github.com/gideros/Button).

    Likes: tytadas

    +1 -1 (+1 / -0 )Share on Facebook
  • None of the solutions helped me. I imported the button.lua file and in the Call Order the button.lua is being called first, the error is just now bigger..
    button.lua:98: bad argument #1 to 'contains' (Sprite expected, got nil)
    stack traceback:
    	button.lua:98: in function 'updateVisualState'
    	button.lua:17: in function 'init'
    	[string "property.lua"]:52: in function '__new'
    	[string "property.lua"]:59: in function 'new'
    	mainsc.lua:21: in function <mainsc.lua:18>
    	plug/scenemanager.lua:253: in function 'dispatchEvent'
    	plug/scenemanager.lua:278: in function 'changeScene'
    	main.lua:20: in main chunk
    Idk lol
  • n1cken1cke Maintainer
    Accepted Answer
    @tytadas: you should create buttons with `Button.new(upState, downState)` where upState and downState are 2 sprites, one to show released button and another to show pressed button. And in your code you pass to `Button.new` only one sprite, for example:
    local startbut = Button.new(Bitmap.new(Texture.new("buttons/login.png")))
    Add second sprite to `Button.new`:
    local startbut = Button.new(Bitmap.new(Texture.new("buttons/login.png")), Bitmap.new(Texture.new("buttons/login.png")))
    Fix each `Button.new` call in your code and it should work :)

    Likes: tytadas

    +1 -1 (+1 / -0 )Share on Facebook
  • The strangest part here is that when I add this line:
    self:addEventListener("enterEnd", self.onEnterEnd, self)
    Error is instantly displayed, but without the line my code works well, just buttons aren't being displayed on the mainsc.. This is strange
  • Okei, let me try
  • muromuro Member
    edited November 2016
    @tytadas, you can try to delete button.lua from the project tree and re-import again. When a project folder or a file are moved to different path, similar error shows up

    Likes: tytadas

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.