你好我正在使用 Marmalde Quick,所以 lua 来创建游戏。
在我的游戏中,当屏幕的一个公园在 tuched 中时,它会创建一个新的音符并将该音符添加到物理中。
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()
但这只会删除最后创建的而不是我想全部删除,有没有办法做到这一点。
谢谢