【问题标题】:How to make sprites fit the entire screen of more than one device如何使精灵适合多个设备的整个屏幕
【发布时间】:2016-10-30 23:09:51
【问题描述】:

我使用 corona 已经有一段时间了,我想知道如何制作一个精灵(使用纹理打包器)并将其设置为我的应用程序的背景。我还希望它能够适应尽可能多的设备,而不会裁剪出任何精灵内容。简而言之,我希望精灵成为适合整个屏幕的背景,而不会丢失任何精灵的内容

【问题讨论】:

    标签: coronasdk sprite-sheet texturepacker


    【解决方案1】:

    希望对你有帮助:

    local _W = display.actualContentWidth
    local _H = display.actualContentHeight
    
    local bg = display.newImage( 'bg.jpg' )
    bg.x, bg.y = display.contentCenterX, display.contentCenterY
    
    
    local mode = 'inside'
    
    -- the image will fill the device width/height exactly
    if mode == 'stretch' then
        bg.width, bg.height = _W, _H
    
    -- the image will be scaled proportionally to fit inside the device width/height
    elseif mode == 'inside' then
        local scale = math.min( _W / bg.width, _H / bg.height )
        bg:scale(scale, scale)
    
    -- the image will be scaled proportionally to completely fill the area, 
    -- allowing portions of it to exceed the bounds defined by device width/height
    elseif mode == 'outside' then
        local scale = math.max( _W / bg.width, _H / bg.height )
        bg:scale(scale, scale)
    end
    

    【讨论】:

    • 感谢您的回复。您能否解释一下您的代码,以便我了解它的作用?
    • 加载图像 (bg.jpg) 并设置为中心位置。更改 de 模式并查看结果(“拉伸”、“内部”或“外部”): - 拉伸:图像将完全填充设备的宽度/高度; - 内部:图像将按比例缩放以适合设备宽度/高度; - 外部:图像将按比例缩放以完全填充该区域,允许其部分超出设备宽度/高度定义的范围。
    猜你喜欢
    • 2014-08-22
    • 2015-03-31
    • 1970-01-01
    • 1970-01-01
    • 2020-05-21
    • 2015-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多