object hits to test for

How do I test for collisions in main.lua in corona sdk when the objects to test for are defined in another class?
I have an image in player class, and an image in enemy class. In main how do I detect if these images collide?

local function onGlobalCollision (event)

if ( event.phase == “began” ) then

print( "began: " … event.object1.myName … " & " … event.object2.myName )

end

end

Runtime:addEventListener( “collision”, onGlobalCollision )
[import]uid: 138547 topic_id: 25449 reply_id: 325449[/import]

This line needs to reference the myName of an object somehow?

event.object1.myName [import]uid: 138547 topic_id: 25449 reply_id: 102879[/import]

This example shows many of the aspects of the mechanics in question:
http://developer.anscamobile.com/code/quick-bubble-popper

See if this can help you along. [import]uid: 21331 topic_id: 25449 reply_id: 102888[/import]

sorry I didnt follow this example.
I think the problem is I have 3 files

  • main
  • player
    -enemy

I need to find out if a collision occurs with the images in different classes and collision detected in main.

It works easy if I put all the images in main but I wanted a OOP structure . [import]uid: 138547 topic_id: 25449 reply_id: 102974[/import]

Hmmm…that’s strange, as the example shows how to pass a collision handler located in main to another module or class and have it’s events handled in main.

I would not use a global listener, I would use table listeners as shown in the example.

Sorry I couldn’t be of more help.
[import]uid: 21331 topic_id: 25449 reply_id: 103054[/import]

I will have another look but i got what i wanted to work.

I just needed to have the image and its name located in the main. I tested it with both listeners. I will try to pass these images to a separate class and test this. [import]uid: 138547 topic_id: 25449 reply_id: 103064[/import]