【问题标题】:Displaying background image in corona sdk在 corona sdk 中显示背景图像
【发布时间】:2016-02-12 17:04:21
【问题描述】:

我正在学习 corona sdk 来制作一个简单的游戏。我要做的第一件事是显示背景图片。

我在corona sdk中新建了一个项目,写了如下代码

local background = display.newImage("background.png")

这段代码在屏幕左上角给出了一个小图片,如下图所示。我尝试了很多其他平台和 youtube 上所说的东西,但找不到答案。

我在上面的代码之后得到的图片

【问题讨论】:

    标签: lua coronasdk


    【解决方案1】:

    试试这个:

    local image = display.newImageRect( "images/background.jpg",
                   display.contentWidth, display.contentHeight) 
    image.x = display.contentCenterX
    image.y = display.contentCenterY
    

    【讨论】:

      【解决方案2】:

      默认情况下,显示图像的定位基于其在网格上 Point(0,0) 的中心点。点 (0,0) 从左上角开始,因此背景的中心位于屏幕的左上角是有意义的。

      有两种方法可以解决您的问题:

      1. 设置 displayObject.anchorX = 0, displayObject.anchorY = 0 使显示图像的左上角位于屏幕的左上角。
      2. 不要设置锚点。而是将 displayObject.x 和 displayObject.y 设置为屏幕的中心。

      【讨论】:

        【解决方案3】:

        试试这个,

        local image = display.newImageRect( "image.png", 100, 100 )
        image.x = display.contentCenterX
        image.y = display.contentCenterY
        

        尝试使用 newImageRect 而不是 newImage。

        https://docs.coronalabs.com/api/library/display/newImageRect.html#examples

        【讨论】:

          猜你喜欢
          • 2015-09-02
          • 1970-01-01
          • 2013-02-03
          • 2014-06-16
          • 1970-01-01
          • 1970-01-01
          • 2013-04-30
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多