我是日惹新手,我正在尝试在标签场景中创建一个gps。我创建了一个局部变量loc,它将放置位置数据字符串
local loc = "Loading" -- as initial value
then a location handler put a new value to it
local function locationHandler( event )
...
loc = "the gps location"
end
function scene:createScene( event )
local group = self.view
-- create a white background to fill screen
local bg = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
bg:setFillColor( 255 ) -- white
local title = display.newRetinaText(loc, 0, 0, native.systemFont, 20 )
-- this is where the loc is placed in the title
title:setTextColor( 0 ) -- black
title:setReferencePoint( display.CenterReferencePoint )
title.x = display.contentWidth * 0.5
title.y = 170
end
问题是当loc在设备中运行时仍然包含“正在加载”它在模拟器中工作。我检查过并且gps工作正常,应该放入loc变量的文本准备进入内部处理程序,使用logcat检查。
我做错了什么?
感谢
答案 0 :(得分:0)
此代码:
local title = display.newRetinaText(loc, 0, 0, native.systemFont, 20 )
复制 loc 变量并将其传递给RetinaText。要更改标题,请使用
title.text = "new text"
考虑这个例子:
local test = "1"
local function change( test )
test = "2"
end
print(test)
change(test)
print(test)
打印:
1
1