【问题标题】:Drawing lines in love2d crashes program在love2d崩溃程序中画线
【发布时间】:2021-08-03 06:02:34
【问题描述】:

我正在尝试使用love.graphics.line 用love2d 绘制一个六边形网格,但是在绘制了大约15000 行之后,程序崩溃了,只有一条消息abort (core dumped)

function love.load()
    ww, wh = love.graphics.getDimensions()
    hexradius = 10
    size = 50

    hexgrid = newGrid(hexradius, size, size) 
end

function love.draw(dt)
    drawgrid()
end

function drawgrid()
    local jxOffset = hexgrid.rad * -math.tan(math.pi/1.5) 
    local ixOffset = jxOffset/4
    local iyOffet = jxOffset * math.sin(math.pi/3)


    for i=1,hexgrid.size.x do
        for j=1,hexgrid.size.y do
            love.graphics.push()
        
            love.graphics.translate(ixOffset + j * jxOffset, i * iyOffet)
            love.graphics.line(
                hexgrid.hex[1].x, hexgrid.hex[1].y,
                hexgrid.hex[2].x, hexgrid.hex[2].y,
                hexgrid.hex[3].x, hexgrid.hex[3].y,
                hexgrid.hex[4].x, hexgrid.hex[4].y,
                hexgrid.hex[5].x, hexgrid.hex[5].y,
                hexgrid.hex[6].x, hexgrid.hex[6].y,
                hexgrid.hex[1].x, hexgrid.hex[1].y)

            love.graphics.pop()
        end

        ixOffset = -ixOffset
    end
end

function newGrid(rad, xsize, ysize)
    local g = {
        rad = rad,
        hex = {},
        size = {
            x = xsize,
            y = ysize,
        },
    }

    for i=1,6 do
        local dir = math.pi/3 * (i+0.5)

        g.hex[i] = {}
        g.hex[i].x = g.rad * math.cos(dir)
        g.hex[i].y = g.rad * math.sin(dir)
    end

    return g
end

总的来说,我对 love2d 和图形的东西还很陌生,所以也许我正在尝试绘制大量线条,但这是不可能的,但我生成的网格似乎没有那么大。我正在使用 LOVE 11.3。

提前致谢!

【问题讨论】:

  • 通常,核心转储表明主机程序中存在错误。考虑在github.com/love2d/love/issues 提交错误报告。此外,我无法在 LOVE 11.1 上重现此问题,因此安装旧版本可能会有所帮助。
  • 你走对了!

标签: graphics lua love2d hexagonal-tiles


【解决方案1】:

我会尝试用多边形来代替,看看你是否有更好的结果。

love.graphics.polygon( mode, vertices )

https://love2d.org/wiki/love.graphics.polygon

for i = 1, hexgrid.size.x do
    for j = 1, hexgrid.size.y do
        love.graphics.push()

        love.graphics.translate( ixOffset +j *jxOffset,  i *iyOffet )
        love.graphics.polygon( 'line', 
            hexgrid.hex[1].x,  hexgrid.hex[1].y,
            hexgrid.hex[2].x,  hexgrid.hex[2].y,
            hexgrid.hex[3].x,  hexgrid.hex[3].y,
            hexgrid.hex[4].x,  hexgrid.hex[4].y,
            hexgrid.hex[5].x,  hexgrid.hex[5].y,
            hexgrid.hex[6].x,  hexgrid.hex[6].y  )

        love.graphics.pop()
    end
...

或者,使用可选的segment 参数集@6 绘制的圆,绘制六边形。

love.graphics.circle( mode, x, y, radius, segments )

https://love2d.org/wiki/love.graphics.circle

for i = 1, hexgrid.size.x do
    for j = 1, hexgrid.size.y do
        love.graphics.circle( 'line', ixOffset +j *jxOffset, i *iyOffet, hexradius, 6 )
    end
...

【讨论】:

  • 两者都爱崩溃,但非常感谢您提供的替代方案!
【解决方案2】:

正如 Luther 在评论中建议的那样,这是 Löve 中的一个错误。它已经修复,将在下一个版本的 Löve 11.4 中提供。

谢谢!

【讨论】:

    猜你喜欢
    • 2020-01-03
    • 1970-01-01
    • 1970-01-01
    • 2019-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多