将MapView置于背景 - Corona SDK

我在 Corona SDK 中需要地图视图方面的帮助。我想将地图作为背景(但带有所有功能),并在这种情况下将一个按钮放在前面。这是我的代码:

function scene:createScene( event )
    local group = self.view

    if ( system.getInfo( "environment" ) == "simulator" ) then
        local simulatorMessage = "Maps not supported in Corona Simulator.\nYou must build for iOS or Android to test native.newMapView() support."
        local label = display.newText( simulatorMessage, 36, 40, 270, 0, native.systemFont, 12 )
        label.anchorX = 0
        label.anchorY = 0
    end

    myMap = native.newMapView( 20, 20, display.contentWidth, display.contentHeight )

    if ( myMap ) then
        myMap.mapType = "normal"
        myMap.x = display.contentCenterX
        myMap.y = display.contentCenterY
        myMap:setCenter( currentLatitude, currentLongitude )
        myMap:addEventListener("mapLocation", mapLocationListener)
    end

    backBtn = widget.newButton
    {
        id="backButton",
        label="Back",
        fontSize="30",
        labelColor={ default={1, 1, 1}, over={0, 0, 0, 0.5} },
        defaultFile="images/button.png",
        width = dispWidth * 0.25, height = dispHeight * 0.1,
        onRelease = onBackBtnRelease
    }
    backBtn.anchorX = 0.5
    backBtn.anchorY = 0.5
    backBtn.x = display.contentWidth * 0.8
    backBtn.y = dispHeight * 0.8
    backBtn:toFront()

    group:insert( backBtn )
    group:toFront() --second try to put that button to front
end

由于 MapView 是本地对象,我无法将其添加到任何组中,'mapView:toBack()' 也无法运行('attempt to index upvalue 'myMap' (a nil value)')。在 Corona SDK 中,按钮出现在没有地图的情况下,与预期相符。在设备上,我得到了没有我的按钮的地图,这不是我期望的结果。

有没有可能将本地对象放到后面,或强制将某些内容放在最前面?

点赞
用户1078537
用户1078537

使用 CoronaSDK 目前无法实现你希望的地图和按钮功能。

事实上,MapView 是一个原生对象。根据 Corona 的文档,你无法将其他对象放置在 MapView 上方。

文档中强调:

地图对象和其他原生显示对象一样,不能插入到组中,并始终显示在常规显示对象(组、向量、图像和文本)的顶部。

在这里查看文档

祝你编写愉快。

2014-07-21 22:55:10
用户2653067
用户2653067

首先检查以下内容:

如果在设备上按钮未出现,最常见的问题可能是,您可能拼错了图像名称(检查是否使用了大小写),或者检查文件的路径是否正确。

要详细了解mapView,请参阅:http://docs.coronalabs.com/api/library/native/newMapView.html

我知道您可能已经访问过了,最好再看看。

谢谢,

2014-07-24 07:11:55