我刚接触Coronoa和Lua,我想知道如何关闭地图和文本框。地图和文本框出现在主屏幕上,我可以创建一个按钮(只是一个普通的黑色x),并使其关闭,但我无法让地图或文本框关闭。下面是我正在使用的代码片段,但我被卡住了。我搜索了谷歌,并通读了他们的文档,我只是遗漏了一些东西。
local obj = display.newImageRect( "closeButton.jpg" ,25,25 )
obj.x = 60
obj.y = 410 -- replaced with newImageRect for dynamic scaling (adjust X & Y as required)
obj.touch = function (event)
local btn = event.target
if event.phase == "ended" then
btn.alpha = 0 -- example to show the function doing something
myMap.alpha = 0
textBox.alpha = 0
end
end
-- begin detecting touches
obj:addEventListener( "touch", obj.touch)
myMap = native.newMapView( 25, 0, 275, 180 )
myMap.mapType = "hybrid" -- other mapType options are "satellite" or "hybrid"
myMap.isScrollEnabled = true
myMap.isZoomEnabled = true
myMap.isLocationUpdating = true
isVisible = myMap.isLocationVisible
myMap:setCenter( 38.354614, -81.726351 )
myMap:addMarker( 38.354614, -81.726351)
-- Adding the Text Box that contains the Directions
textBox = native.newTextBox( 22, 183, 280, 225 )
textBox.text = "blah blah blah boring directions."
local group = display.newGroup()
group:insert( obj )我一直收到“尝试索引本地'myMap‘(一个nil值)”,textBox也出现了同样的错误。因此,如果有人能提供帮助,我们将不胜感激。
发布于 2013-03-12 19:13:11
在本地声明'MapView‘和'textBox’在'obj.touch‘函数之上,如下所示:
local myMap;
local textBox;注意:模拟器中不支持 mapView。
继续编码.............
https://stackoverflow.com/questions/15323995
复制相似问题