将按钮设为* .lua文件的最简单方法是什么?
我想制作类似的东西:main.lua(点击按钮) - > scene1.lua(BACK点击按钮) - > main.lua
我试过这样的事情:
local storyboard = require ("storyboard")
local scene = storyboard.newScene()
local logo tlo = display.newImage("bg.png", 360, 640)
local zamow = display.newImage("1zamow.png", 185, 340)
local gadgety= display.newImage("2gadgety.png", 535, 340)
local facebook = display.newImage("3facebook.png", 185, 700)
local oferta = display.newImage("4oferta.png", 535, 700)
local cennik = display.newImage("5cennik.png", 185, 1060)
local kontakt = display.newImage("6kontakt.png", 535, 1060)
function cennik:touch (event)
storyboard.gotoScene("cennik", "fade", 400)
end
cennik:addEventListener( "touch", cennik )
return scene'
之后我有运行时错误:
尝试连接全局' sceneName' (零值)
我是Corona的新人,所以请保持友善:)
答案 0 :(得分:0)
最好使用widget创建按钮。如果cennik是您的按钮图像而scene1.lua是下一页,则代码将写为
local storyboard = require ("storyboard")
local widget=require "widget"
local scene=storyboard.newScene()
local logotlo = display.newImage("bg.png", 360, 640)
local zamow = display.newImage("1zamow.png", 185, 340)
local gadgety= display.newImage("2gadgety.png", 535, 340)
local facebook = display.newImage("3facebook.png", 185, 700)
local oferta = display.newImage("4oferta.png", 535, 700)
local kontakt = display.newImage("6kontakt.png", 535, 1060)
local cennikBtn
local function onStartButtonRelease()
storyboard:gotoScene("scene1")
end
cennikBtn = widget.newButton {
defaultFile="5cennik.png",
onRelease=onStartButtonRelease
}
cennikBtn.x,cennikBtn.y =185, 1060
function scene:createScene(event)
local group = self.view
group:insert(logotlo)
group:insert(zamow)
group:insert(gadgety)
group:insert(facebook)
group:insert(oferta)
group:insert(kontakt)
group:insert(cennikBtn)
end
function scene:enterScene( event )
local group = self.view
end
function scene:exitScene( event )
local group = self.view
storyboard.removeScene("main")
end
function scene:destroyScene( event )
local group = self.view
end
scene:addEventListener( "createScene", scene )
scene:addEventListener( "enterScene", scene )
scene:addEventListener( "exitScene", scene )
scene:addEventListener( "destroyScene", scene )
return scene
答案 1 :(得分:0)
除'
之后的return scene
以外,您的代码看起来很好,您的事件处理程序需要像这样:
-- For each time you tap the image, this event gets triggered twice. Make sure you only dispatch your gotoScene once!
function cennik:touch(event)
if event.phase == "began" then
-- This happens on finger touching
elseif event.phase == "ended" then
-- This happens when the finger is lifted
storyboard.gotoScene("cennik", "fade", 400)
end
-- if you want to prevent the touch event from propagating (aka triggering other images touch event) you must return true
return true
end