Collisions Involving Objects

I’m using Corona SDK to create a game that features a moving ball that can collide with other things. I decided to use objects (in the OOP sense) to create the things the ball can collide with. I’m using objects because the things the ball can collide with are made up of multiple elements that can explode into parts on impact. I think using objects will make managing the elements easier.

I followed this tutorial on creating classes. For testing purposes, my class includes a rectangle created with [lua]display.newRect[/lua] for the ball to collide with. I am using [lua]event.other[/lua] inside the event listener function to access the object the ball collided with, which is a rectangle in this case.

This, of course, seems to give me a reference to the rectangle the ball hit, but what I really want is access to the rectangle’s parent object. I tried to access the parent object using [lua]event.other.parent[/lua], but this returns [lua]nil[/lua]. Next, I created a property of the rectangle in the class to store a reference to the parent object, like this: [lua]self.MyRectangle.ParentObject = self[/lua]. In my listener function, I then used [lua]event.other.ParentObject[/lua] to access the object.

Using [lua]event.other.ParentObject[/lua] returns an object of the type expected, but it is not the parent of the rectangle the ball hit. The object seems to be a new object created with the class’s constructor.

Does anyone know what I’m doing wrong and how I can access these objects? [import]uid: 179568 topic_id: 36336 reply_id: 336336[/import]