0

こんにちは Marmalde Quick を使用しているので、lua でゲームを作成します。

私のゲームでは、画面のパークがタッチされたときに、新しいメモが作成され、そのメモが物理演算に追加されます。

    function bgTouched(event)
        if (director:getCurrentScene() == gameScene) then
      if (gameState == gameStates.playing) then 
        if event.phase == "began" then
          addToRoundScore()
            if bodyType == 0 then
                -- Create object1
                b = director:createSprite(event.x, event.y, "textures/beachball.png")
                b.name = "ball"
                b.strokeWidth=0
                b.xAnchor = 1; b.yAnchor = 0 -- test non-0 anchor point for circle
                physics:addNode(b, {radius=40})
            elseif bodyType == 1 then
                -- Create object2
                b = director:createSprite(event.x, event.y, "textures/crate.png")
                b.name = "crate"
                b.strokeWidth=0
                b.xAnchor = 0; b.yAnchor = 0.5 -- test non-0 anchor point for rectangle
                b.xScale = 2; b.yScale = 1 -- test different scale
                physics:addNode(b, {} )
            elseif bodyType == 2 then
                -- Create obejct3
                b = director:createSprite(event.x, event.y, "textures/triangle.png")
                b.name = "tri"
                b.xAnchor = 0.5; b.yAnchor = 1 -- test non-0 anchor point for polygon
                physics:addNode(b, {shape={0,0, 95,0, 48,81}} )end

        b.rotation = 22.5
        bodyType = (bodyType + 1) % 3

    end
  end

  end

end
bg:addEventListener ("touch", bgTouched) 

イベントが発生したときに、作成したすべてのメモを削除したいので、次を使用してみました。

physics:removeNode(b)
b:removeFromParent()

しかし、これは最後に作成されたものを削除するだけで、すべてを削除したくありません。これを行う方法はありますか。

ありがとう

4

1 に答える 1

1

ノードを追加する処理の前にノード テーブルをクリアしたいということを正しく理解している場合はevent.phase == "began"、物理テーブルをリセットできます。

physics = {}

コードの他の部分が物理ノードを参照していて、物理ノードが新しいテーブルを指していることを通知できない場合は、テーブルのすべての項目をループして nil にすることができます。

for k,v in pairs(physics)
    physics[k] = nil
end
于 2013-12-23T14:15:22.320 に答える