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
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
Likes: tytadas
Likes: tytadas