在方格中突出显示路径

在我的基于方格的游戏中,玩家点击一个单位,然后移动手指确定该单位应该移动到哪里。我正在使用"Jumper"库进行路径查找。获取路径的代码完美运行,但突出路径的代码不尽如人意。

local function onTileTouch( event )
    local phase = event.phase
    local tile = event.target

    if ( phase == "began"  ) then
        -- 我可以在这里创建直线
    elseif ( phase == "moved" ) then
        createPath( tile )

        -- 获取第一个方格的位置,基于该单元的位置
        local t = tiles[currentSelectedUnit.pos.y][currentSelectedUnit.pos.x]

        -- 在第一个方格位置处创建线路
        line = display.newLine( t.x, t.y, t.x, t.y )
        line:setStrokeColor( 1,0,0 )
        line.strokeWidth = 8

        -- "foundPath" 是正确路径的方格表
        for i=1,#foundPath do
            line:append( foundPath[i].x,foundPath[i].y )
        end
    elseif ( phase == "ended" or phase == "cancelled" ) then
end

在“移动”阶段创建线路时,线路看起来不正确。然而,在“开始”阶段创建并在“移动”阶段添加时,它看起来非常准确。但是,在这种情况下,还会绘制另一条不遵循路径而是直接从起始方格到终止方格的额外线路。 我对“开始”阶段方法的第二个问题是,我不知道如何保持删除旧线并为新的正确路径创建新线。

如果需要任何额外信息,请告诉我。

点赞