【问题标题】:Corona SDK Storyboard doesn't transit into scenesCorona SDK 故事板不会转入场景
【发布时间】:2013-07-20 08:17:13
【问题描述】:

我正在创建一个主菜单,我想用故事板处理我的场景。

这是我的 main.lua:

-- Hide status bar
display.setStatusBar(display.HiddenStatusBar);

-- Some global variables
local assetsPath = "media/"
local lettersPath = "media/letters/"

-- Initialize storyboard
local storyboard = require ("storyboard")
local widget = require("widget")

-- Load first scene
storyboard.gotoScene("splashscene")

这是我的splashscene.lua:

本地故事板 = 要求(“故事板”) 本地场景 = storyboard.newScene()

本地 bgimg、moratechlogo、文本

本地函数onSceneTouch(self,event)

if event.phase == "began" then

    storyboard.goToScene("mainmenuscene", "fade", 400)

    return true
end 

结束

函数场景:createScene(event)

local screenGroup = self.view

bgimg = display.newImage("media/splashBG.png",0,0)
moratechlogo = display.newImage("media/moratechgames.png", display.contentWidth/2 - 150, display.contentHeight/2 - 100)
screenGroup:insert(bgimg)
screenGroup:insert(moratechlogo)
moratechlogo.touch = onSceneTouch


text = display.newText("Tap here to continue...", display.contentWidth /2 - 76, display.contentHeight - 30)
text:setTextColor(255)
screenGroup:insert(text)

text.touch = onSceneTouch

结束

函数场景:enterScene(事件) local screenGroup = self.view

结束

函数场景:exitScene(事件)

-- remove touch listener for image text:removeEventListener( "touch", text ) moratechlogo:removeEventListener("touch",moratechlogo) end function scene:destroyScene( event ) end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene

但是当我单击/触摸文本和/或徽标时,它不会传输到 mainmenuscene.lua 知道为什么吗?

【问题讨论】:

  • 也许我忘记在徽标和文本中添加事件监听器了?
  • 是的,我做到了。但现在它告诉我:尝试去 goToScene(一个 nil 值)。这是为什么呢?

标签: lua coronasdk corona-storyboard


【解决方案1】:

好吧,显然我忘了在 enterScene 方法中将事件监听器添加到徽标和文本中。 另外,我打错了“gotoScene”,而是写成了“goToScene”。

问题已解决。

【讨论】:

    【解决方案2】:

    您也可以尝试使用widget.newButton http://docs.coronalabs.com/api/library/widget/newButton.html

    按钮有标签、背景图片等选项!

    local widget = require( "widget" )

    local button1 = widget.newButton { left = 100, top = 200, id = "button1", label = "Default", onPress = function() storyboard.gotoScene( "scenes", {effect="someEffect", time=someTime ) }

    如果您创建了任何其他函数,例如 storyboard.hide_someObject(),您可以将其放在 storyboard.gotoScene 的正下方,当您按下按钮时,它会在 onPress 发生

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-19
      • 1970-01-01
      • 2016-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-22
      • 1970-01-01
      相关资源
      最近更新 更多