Detecting multiple object position

Hi.

I have an app that uses physics for multiple objects to interact with each other, so they collide when 

they bumped into each other. Each object is also assigned with touch listeners, so I can track their movement via terminal.

my question is, is it possible to loop throughout the runtime, to check every movement that happens in the screen? for example, I have object A and object B. whenever object B is moved because of bumping with object A, I can detect both of those 2 objects x and y. Is it possible?

Hello,

I’m not sure what you mean by this. It’s easily possible to detect all objects involved in any collision and get any properties for them, including x and y. Is there something more that you need to accomplish with collisions?

Best regards,

Brent

thanks for replying brent.

What I want to do is to trigger whenever there are collision happening, which I just read that there are collision event listeners on Corona. my bad for not reading.

The other question that I want to ask is whether a collision happen, i can detect x and y of the 2 collided object, is that possible? or maybe if it is collided into more than 2 objects.

The values .x and .y are always available on every display object, so you don’t need any special logic for that.

Perhaps you want the actual location of the collision point? If so, you still need to take a look at the API documentation:

http://docs.coronalabs.com/api/library/physics/setReportCollisionsInContentCoordinates.html

It sounds like you should take a look at the Samples/Physics directory which comes with the Corona SDK application.

What I want to know is not the collision position, but the position of the object itself after collision, or during collision. i want to update constantly so I can attach a listener whenever an object has reached certain position.

For example, I move obj A into B. during the collision, i need to know the x and y for obj A and B when they are colliding, updating every time they both move. or something like that.

As I said, the values .x and .y are always available on every display object, so you don’t need any special logic for that.

If you want to check the position of an object constantly you could use an enterFrame listener, but I don’t advise that as there arm can be serious performance penalties involved.

If you just want to know when A has reached location B then simply have a transition to move it - when the transition ends you know it’s there.

If you’re not controlling A’s position you could attach small sensor objects to A and B - when they touch you know A is at B’s given point.

Other than that a very quick if statement in enterFrame would work, just be careful not to do too much or your frame rate will suffer.

Thanks for patiently explaining horacebury. i still got some more questions, if you don’t mind.

i try to apply physics to both objects, and I want them to update their positions whenever there are events, such as collisions. using enterFrame, as you said, will suffer great in performance. But I haven’t had a slightest idea of creating a listener that triggered when position of an object is moved. If I am using collision listener, which coordinate will I receive? When the collision happen? after collision happened?

If I use touch listener, I can’t get update on position for objects that are not touched. If I use collision, I am not sure which coordinate will be given from which event. :frowning:

It seems that you are searching for a “moved” event listener, which does not exist. Actually monitoring an object’s position with an enterFrame listener is not expensive enough to avoid doing it, just be careful that you don’t add too much to the logic.

Think about what it is that you really need to check. Is it really that you need to know when the object moves? Or do you simply need to know when the object is at a particular location on the screen? If it is that you need to know when two objects are in a certain location relative to each other, this is another scenario.

Can you explain what you’re trying to build from a gamer’s viewpoint and maybe I can suggest a way to do it without trying to solve the problem from a blind code viewpoint.

okay. let me explain from a gamer viewpoint, so probably it will help explaining what I need.

I want to make a puzzle game, where you have several different objects with different shapes and colors, and there are some holes on the screen. The objective is to put the right object into the right hole. 

Naturally, when you drag the object nearing the hole, it will detect the object and verified if it is the right object, then it will enter the hole. But, just like real objects, these puzzles are physical. They can bump into other puzzles, and what I want to do is: when one puzzle is being ‘pushed’ using another puzzle into the right hole, it will also check for every object that is moving toward the hole. So even if you don’t touch the object that you need to put into the right hole, you can ‘push’ it using other puzzle. a concept that is similar to billiard, perhaps?

I hope this helps clearing the problem. :slight_smile:

Ok, I think you should take a look at the Pool sample in the CoronaSDK/Samples/Physics directory. Try making the balls draggable with a physics touch joint.

I think this will accomplish what I need. I’ll try to read. big thanks for the pointers :slight_smile:

Hello,

I’m not sure what you mean by this. It’s easily possible to detect all objects involved in any collision and get any properties for them, including x and y. Is there something more that you need to accomplish with collisions?

Best regards,

Brent

thanks for replying brent.

What I want to do is to trigger whenever there are collision happening, which I just read that there are collision event listeners on Corona. my bad for not reading.

The other question that I want to ask is whether a collision happen, i can detect x and y of the 2 collided object, is that possible? or maybe if it is collided into more than 2 objects.

The values .x and .y are always available on every display object, so you don’t need any special logic for that.

Perhaps you want the actual location of the collision point? If so, you still need to take a look at the API documentation:

http://docs.coronalabs.com/api/library/physics/setReportCollisionsInContentCoordinates.html

It sounds like you should take a look at the Samples/Physics directory which comes with the Corona SDK application.

What I want to know is not the collision position, but the position of the object itself after collision, or during collision. i want to update constantly so I can attach a listener whenever an object has reached certain position.

For example, I move obj A into B. during the collision, i need to know the x and y for obj A and B when they are colliding, updating every time they both move. or something like that.

As I said, the values .x and .y are always available on every display object, so you don’t need any special logic for that.

If you want to check the position of an object constantly you could use an enterFrame listener, but I don’t advise that as there arm can be serious performance penalties involved.

If you just want to know when A has reached location B then simply have a transition to move it - when the transition ends you know it’s there.

If you’re not controlling A’s position you could attach small sensor objects to A and B - when they touch you know A is at B’s given point.

Other than that a very quick if statement in enterFrame would work, just be careful not to do too much or your frame rate will suffer.

Thanks for patiently explaining horacebury. i still got some more questions, if you don’t mind.

i try to apply physics to both objects, and I want them to update their positions whenever there are events, such as collisions. using enterFrame, as you said, will suffer great in performance. But I haven’t had a slightest idea of creating a listener that triggered when position of an object is moved. If I am using collision listener, which coordinate will I receive? When the collision happen? after collision happened?

If I use touch listener, I can’t get update on position for objects that are not touched. If I use collision, I am not sure which coordinate will be given from which event. :frowning:

It seems that you are searching for a “moved” event listener, which does not exist. Actually monitoring an object’s position with an enterFrame listener is not expensive enough to avoid doing it, just be careful that you don’t add too much to the logic.

Think about what it is that you really need to check. Is it really that you need to know when the object moves? Or do you simply need to know when the object is at a particular location on the screen? If it is that you need to know when two objects are in a certain location relative to each other, this is another scenario.

Can you explain what you’re trying to build from a gamer’s viewpoint and maybe I can suggest a way to do it without trying to solve the problem from a blind code viewpoint.

okay. let me explain from a gamer viewpoint, so probably it will help explaining what I need.

I want to make a puzzle game, where you have several different objects with different shapes and colors, and there are some holes on the screen. The objective is to put the right object into the right hole. 

Naturally, when you drag the object nearing the hole, it will detect the object and verified if it is the right object, then it will enter the hole. But, just like real objects, these puzzles are physical. They can bump into other puzzles, and what I want to do is: when one puzzle is being ‘pushed’ using another puzzle into the right hole, it will also check for every object that is moving toward the hole. So even if you don’t touch the object that you need to put into the right hole, you can ‘push’ it using other puzzle. a concept that is similar to billiard, perhaps?

I hope this helps clearing the problem. :slight_smile:

Ok, I think you should take a look at the Pool sample in the CoronaSDK/Samples/Physics directory. Try making the balls draggable with a physics touch joint.