2017-10-03 5 views
0

私は六角形のグリッドベースのゲームを作ろうとしています。私は基本的なものをいくつか持っています(図書館はそれをネイティブに持たず、個々の六角形を色づけることができるので、六角形の隣り合わせを実装しました)。しかし、私は一つのことをすることはできません:周囲の六角形を「線」塗りつぶしモードに変更する

私は六角形の上にマウスを置くと、周囲のネイバーが行の塗りつぶしモード(picture example)に変更されます(マウスが左上の六角形の上にあると仮定します)。しかし、それらを 'fill'に戻す方法を理解できないようです'私はそれの上に浮遊を停止したとき。

ここでは、関連するコード(私は近隣諸国との六角形やお得な情報の上にマウスを移動していた場合、ハンドルチェック)です:

function love.update() 
    mx, my = love.mouse.getPosition() 
    if hexGrid:containingHex(mx, my)~=nil then --am I hovering over a hexagon? 
     local q,r=hexGrid:containingHex(mx, my).q,hexGrid:containingHex(mx, my).r -- get the position on the grid for the hexagon 
     local neighbors=hexGrid:neighbors(q,r) -- get neighbors of hexagon I'm hovering over 
     for dir, neighbor in pairs(neighbors) do -- loop through neighbor table 
      if neighbor ~=nil and hexes.getHexagon(hexGrid:getHex(neighbor.q,neighbor.r))["fill"]=="fill" then -- does neighbor exist and is their fill mode "fill"? 
       local neighborHexagon=hexGrid:getHex(neighbor.q,neighbor.r) -- get the hexagon from the grid 
       local neighborData=hexes.getHexagon(neighborHexagon) -- get it's data from a seperate dictionary (stores color data and fill mode data) 
       neighborData["fill"]="line" -- set fill mode to line 
      end 
     end 
    end 
end 

答えて

0

あり、あなたがこれを行うに取り掛かることができ、いくつかの方法がありますが、最も簡単で(IMO)は、すべてのフレームの最後に以前のタイルの状態をリセットします。

更新ループは次のようになります:あなたは私の問題を誤解している場合

-- Reference to the old tile position 
local oldhexagon 

function love.update() 
    mx, my = love.mouse.getPosition() 
    if hexGrid:containingHex(mx, my)~=nil then --am I hovering over a hexagon? 
     -- Check if you were previously over a tile 
     if oldhexagon then 
      -- Set old hexagon's fill mode to line 
     end 

     -- Get rid of the reference for next frame 
     oldhexagon = nil 

     -- etc. 

     oldhexagon = neighborData 
    end 
end 
+0

わかりません。私が上に乗っているものは決して変化しません(例の写真に示されているように)、それは隣人だけです。私は六角形の**隣人**が私がそれの上に浮遊するのをやめたときに元に戻すことを望む。 – Ducktor

+0

@Ducktorだから、明確にするために、マウスが上になければ、六角形が塗りつぶしモードにしたいと思っています。 – DavisDude

関連する問題