0
我打算做一個簡單的遊戲。我的代碼有許多機構在定時器功能(例如每秒):Gideros遊戲引擎box2d機構
local function onTimer()
local sx = 20
local sy = 20
body = world:createBody{type = b2.DYNAMIC_BODY, position = {x = i*48, y = 50}}
local shape = b2.PolygonShape.new()
-- box images are 70x70 pixels. we create bodies 1 pixel smaller than that.
shape:setAsBox(20, 20)
body:createFixture{shape = shape, density = 1, restitution = 0.1, friction = 0.3}
rand = math.random(1,32)
sprite = createBoxSprite(0.6,0.6,rand)
stage:addChild(sprite)
actors[body] = sprite
actors_r[sprite] = body
table.insert(sp, sprite)
--print (sprite)
--print (sp[#sp])
sprite:addEventListener(Event.TOUCHES_BEGIN, onTouchBegin,sprite)
sprite:addEventListener(Event.TOUCHES_END, onTouchEnd,sprite)
i=i+1
all=all+1
--print(all)
if i>8 then
i=1
end
if all>88 then
print("game over")
end
end
我想刪除任何身體的點擊。但是當這個聽衆點擊時,只有所有的精靈都被移除。
function onTouchBegin(e)
e:removeFromParent()
end
function onTouchEnd(e)
end
該怎麼辦?