I am new in corona and i am trying to create a gps inside a tab scene. I created a local variable loc where it is where the string of location data will be placed
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
the problem is loc still contains "Loading" when run in the device it works in the simulator though. I have checked and gps works fine and text that should be put in loc variable is ready to go in the inside handler, checked using logcat.
What am I doing wrong?
thanks
This code:
local title = display.newRetinaText(loc, 0, 0, native.systemFont, 20 )
makes a copy of a loc variable and passes it to RetinaText. To change the title use
title.text = "new text"
Consider this example:
local test = "1"
local function change( test )
test = "2"
end
print(test)
change(test)
print(test)
It prints:
1
1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.