Button 创建*.lua文件的按钮的最简单方法

Button 创建*.lua文件的按钮的最简单方法,button,lua,scene,Button,Lua,Scene,将按钮转换为*.lua文件的最简单方法是什么 我想制作这样的东西:main.lua(点击按钮)-->scene1.lua(后退点击按钮)-->main.lua 我试过这样的方法: local storyboard = require ("storyboard") local scene = storyboard.newScene() local logo tlo = display.newImage("bg.png", 360, 640) local zamow = displ

将按钮转换为*.lua文件的最简单方法是什么

我想制作这样的东西:main.lua(点击按钮)-->scene1.lua(后退点击按钮)-->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'
-- 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
之后,出现运行时错误:

尝试连接全局“sceneName”(一个空值)


我是科罗纳的新人,所以请友好:)

最好使用小部件创建按钮。如果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

除了
返回场景之后的
之外,您的代码看起来很好,并且您的事件处理程序需要如下所示:

  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'
-- 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

必须根据显示的层次结构将所有显示元素添加到CreateSecene函数的组中。在返回场景后有一个
字符。这很糟糕