1

我是电晕的新手,我正在尝试在标签场景中创建一个 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 检查。

我究竟做错了什么?

谢谢

4

1 回答 1

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
于 2013-02-21T15:51:32.360 回答