【问题标题】:Love2d: How to retain window content?Love2d:如何保留窗口内容?
【发布时间】:2018-12-15 01:28:05
【问题描述】:

在love2d 中,屏幕内容在draw 调用之间重置。这样我就无法在最后一次draw 操作期间创建的屏幕上添加一些内容,例如,在上一次迭代期间打印的行下方打印另一行。

如何使用爱情游戏引擎做到这一点。具体来说,我在主游戏区域旁边有一个调试区域,我想在该窗口中打印记录的消息。

其他用例是当玩家获胜(或失败)时在游戏区域上绘制一些效果,在显示对话框时模糊背景。

【问题讨论】:

  • 游戏引擎标签 wiki 说只有在开发自己的引擎或引擎缺少自己的标签时才使用它。 Love2d 有自己的标签。
  • @code11 对。问题相应编辑

标签: loops lua love2d


【解决方案1】:

Love2ds 默认循环调用love.draw,自动清屏。 见https://love2d.org/wiki/love.run

为避免这种情况,您可以使用自己的运行函数并删除 love.graphics.clear() 或者您可以使用画布https://love2d.org/wiki/Canvas。

【讨论】:

    【解决方案2】:

    我不知道可视化调试控制台。但是,可以使用某种着色器方法在绘制调用期间操作像素。 Here 是高斯模糊像素效果的示例:

    local graphics = love.graphics    
    function love.load()    
        local program = ([[
            const float kernel[5] = float[](0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162);
            vec4 effect(vec4 color, sampler2D tex, vec2 tex_coords, vec2 pos) {
                color = texture2D(tex, tex_coords) * kernel[0];
                for(int i = 1; i < 5; i++) {
                    color += texture2D(tex, vec2(tex_coords.x + i * %f, tex_coords.y)) * kernel[i];
                    color += texture2D(tex, vec2(tex_coords.x - i * %f, tex_coords.y)) * kernel[i];
                }
                return color;
            }
        ]]):format(1 / graphics.getWidth(), 1 / graphics.getWidth())
        fx = graphics.newPixelEffect(program)
    
        local program = ([[
            const float kernel[5] = float[](0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162);
            vec4 effect(vec4 color, sampler2D tex, vec2 tex_coords, vec2 pos) {
                color = texture2D(tex, tex_coords) * kernel[0];
                for(int i = 1; i < 5; i++) {
                    color += texture2D(tex, vec2(tex_coords.x, tex_coords.y + i * %f)) * kernel[i];
                    color += texture2D(tex, vec2(tex_coords.x, tex_coords.y - i * %f)) * kernel[i];
                }
                return color;
            }
        ]]):format(1 / graphics.getHeight(), 1 / graphics.getHeight())
        fy = graphics.newPixelEffect(program)
    
    
        print(fx:getWarnings())
        print(fy:getWarnings())
    
    
        canvas_x = graphics.newCanvas(graphics.width, graphics.height)
        canvas_y = graphics.newCanvas(graphics.width, graphics.height)
    end
    
    t = 0
    
    function love.draw()
        t = t + 0.02
        local x = 400 + math.sin(t) * 400
        local y = 300 + math.sin(t * 0.8) * 300    
    
        graphics.setCanvas(canvas_x)
        graphics.push()
        graphics.translate(x, y)
        graphics.rotate(t * 1.3)
        graphics.rectangle("fill", -10, -50, 20, 100)
        graphics.pop()    
    
        graphics.setPixelEffect(fx)
        graphics.setCanvas(canvas_y)
        graphics.draw(canvas_x, 0, 0)
    
        graphics.setPixelEffect(fy)
        graphics.setCanvas(canvas_x)
        graphics.draw(canvas_y, 0, 0)
    
        graphics.setPixelEffect()
        graphics.setCanvas()
        graphics.draw(canvas_x, 0, 0)
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多