How do you distinguish between collisions between different objects? So say if an enemy hits a object, it loses a life, yet if the enemy hits the player, the player loses a life. Thanks.
You can add a variable to the objects that the collision listener can check. For example if you created an enemy object and a player object (images, rectangles, etc.) you could do this:
[lua]
player.tag = “player”
enemy.tag = “enemy”
[/lua]
And then the collision listener can look at these variables like this:
[lua]
local function onPlayerCollision(event) --this function is on the player
--event.other is the object that is colliding with the object the listener is connected to
print(“COLLISION WITH”…event.other.tag)
end
[/lua]
You can add a variable to the objects that the collision listener can check. For example if you created an enemy object and a player object (images, rectangles, etc.) you could do this:
[lua]
player.tag = “player”
enemy.tag = “enemy”
[/lua]
And then the collision listener can look at these variables like this:
[lua]
local function onPlayerCollision(event) --this function is on the player
--event.other is the object that is colliding with the object the listener is connected to
print(“COLLISION WITH”…event.other.tag)
end
[/lua]