检查游戏中的每次碰撞

时间:2014-05-13 22:35:08

标签: lua collision-detection collision gideros

我正在使用Gideros, 这是我必须检查碰撞的代码,但真正发生的是碰撞只打印3次,因为groupA中只有3个成员,我想检查所有3个碰撞,但显然只要游戏正在运行,那么如何检查我的第二个精灵(可爱)碰巧与groupA中分组的3个对象中的任何一个碰撞?

for i = 1, groupA:getNumChildren() do
local sprite = groupA:getChildAt(i) 
local x,y,w,h = groupA:getBounds(stage)
local x2,y2,w2,h2 = cute:getBounds(stage)
if not ((y+h < y2) or (y > y2+h2) or (x > x2+w2) or (x+w < x2)) then
print("collision")
end
end

1 个答案:

答案 0 :(得分:2)

您需要将此循环放在ENTER_FRAME事件中以检查每个帧上的冲突