如何解决Solar2d运行时错误-小部件库和点击栏
我正在使用Solar2d引擎(以前为CoronaSDK),所以它是Lua语言。问题是我正在使用Solar2d为制表栏应用程序提供的预制模板。这是main.lua(我只更改了按钮的标签)
display.setStatusBar( display.HiddenStatusBar )
-- include Corona's "widget" library
local widget = require "widget"
local composer = require "composer"
-- event listeners for tab buttons:
local function onFirstView( event )
composer.gotoScene( "view1" )
end
local function onSecondView( event )
composer.gotoScene( "view2" )
end
-- create a tabBar widget with two buttons at the bottom of the screen
-- table to setup buttons
local tabButtons = {
{ label="Calculator",defaultFile="button1.png",overFile="button1-down.png",width = 32,height = 32,onPress=onFirstView,selected=true },{ label="Curiosities",defaultFile="button2.png",overFile="button2-down.png",onPress=onSecondView },}
-- create the actual tabBar widget
local tabBar = widget.newTabBar{
top = display.contentHeight - 7,-- 50 is default height for tabBar widget
buttons = tabButtons
}
onFirstView() -- invoke first tab button's onPress event manually
简而言之:我们创建了一个视图,该视图的底部带有一个选项卡栏,带有两个按钮,可将您发送到“ view1”(view1.lua)或“ view2”(view2.lua)。 预制模板还包括白色背景和两个视图中的一些文本。 照原样,代码可以正常工作,但是当我将代码插入到view1.lua并替换旧的本地语言(背景和文本)时,出现此错误。 这是view1.lua
local composer = require( "composer" )
local scene = composer.newScene()
local widget = require "widget"
function scene:create( event )
local sceneGroup = self.view
-- Called when the scene's view does not exist.
--
-- INSERT code here to initialize the scene
-- e.g. add display objects to 'sceneGroup',add touch listeners,etc.
display.setDefault( "background",0.1,0.2,0.8)
local numero
local result
local function textListener( event )
if ( event.phase == "ended" or event.phase == "submitted") then
local num1 = tonumber(numero.text)
if (num1) then
result.text = num1 * 343.1
result.size = 60
end
end
end
numero = native.newTextField( display.contentCenterX,150,170,45)
numero:addEventListener( "userInput",textListener )
numero.inputType = "decimal"
result = display.newText( "How many seconds?",display.contentCenterX,320,native.SystemFont)
result:setFillColor(180,180,0)
result.size = 32
local logo = display.newImageRect( "img/fulmenLogo1.png",60,60)
logo.x = 290
logo.y = -14
-- all objects must be added to group (e.g. self.view)
sceneGroup:insert( numero )
sceneGroup:insert( result )
sceneGroup:insert( logo )
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if phase == "will" then
-- Called when the scene is still off screen and is about to move on screen
elseif phase == "did" then
-- Called when the scene is now on screen
--
-- INSERT code here to make the scene come alive
-- e.g. start timers,begin animation,play audio,etc.
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if event.phase == "will" then
-- Called when the scene is on screen and is about to move off screen
--
-- INSERT code here to pause the scene
-- e.g. stop timers,stop animation,unload sounds,etc.)
elseif phase == "did" then
-- Called when the scene is now off screen
end
end
function scene:destroy( event )
local sceneGroup = self.view
-- Called prior to the removal of scene's "view" (sceneGroup)
--
-- INSERT code here to cleanup the scene
-- e.g. remove display objects,remove touch listeners,save state,etc.
end
---------------------------------------------------------------------------------
-- Listener setup
scene:addEventListener( "create",scene )
scene:addEventListener( "show",scene )
scene:addEventListener( "hide",scene )
scene:addEventListener( "destroy",scene )
-----------------------------------------------------------------------------------------
return scene
Corona(实际上是Solar2d)模拟器显示的错误如下:
D:\ a \ corona \ corona \ subrepos \ widget \ widgetLibrary \ widget_tabbar.lua:453:尝试索引字段'?' (零值) 堆栈回溯:
D:\ a \ corona \ corona \ subrepos \ widget \ widgetLibrary \ widget_tabbar.lua:453:在函数'initWithImageSheet'中
D:\ a \ corona \ corona \ subrepos \ widget \ widgetLibrary \ widget_tabbar.lua:849:在函数中
D:\ a \ corona \ corona \ subrepos \ widget \ widgetLibrary \ widget_tabbar.lua:135:在函数中
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。