【问题标题】:Scale image to display.contentWidth,display.contentHeight将图像缩放到 display.contentWidth,display.contentHeight
【发布时间】:2013-06-20 16:24:12
【问题描述】:

如何将图像缩放到屏幕大小?

我尝试过的:

image:scale( display.contentWidth, display.contentHeight )

【问题讨论】:

    标签: image lua coronasdk


    【解决方案1】:

    您可以使用它使图像适合您的屏幕

    local screen_adjustment = 1
    local background = display.newImage("Objects/bg.png", true)
    background.xScale = (screen_adjustment  * background.contentWidth)/background.contentWidth
    background.yScale = background.xScale
    background.x = display.contentWidth / 2
    background.y = display.contentHeight / 2
    

    只需更改 screen_adjustment 的值以适合您的屏幕

    【讨论】:

      【解决方案2】:

      Corona的屏占比是固定的,查看build.lua

      您可以通过更改图像的宽度和高度来做到这一点(它会拉伸图像)

      bg.width = display.contentWidth
      bg.height = display.contentHeight
      bg.x = display.contentWidth / 2
      bg.y = display.contentHeight / 2
      

      您也可以通过使用图像的 xScale 和 yScale 来做到这一点

      注意:如果您想保持图像的 1:1 比例,xScale 和 yScale 必须相同

      这样做可以参考DevfaR的回答

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-08-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-02
        • 2018-03-02
        相关资源
        最近更新 更多