No Title
Shri

Gio,

I saw this in the 3.3 change log - " Added an onOverlap event to SceneObjects "

Let's say I have a scenario where arrows are fired at enemies and I want to figure out if the arrows have hit an enemy. Both arrows and enemies are scene objects.

Currently, I keep an array of arrows, loop through them and for each arrow, call its' getOverlappingObjects() function. Then if there are overlapping objects, I check to see if it has an "isEnemy" attribute.If that is true, then do whatever is supposed to happen when an enemy gets hit by an arrow.

Should I now instead implement and onOverlap() handler in the enemy scene object,  check if the overlapping object has an "isArrow" attribute.and then do whatever is supposed to happen when an enemy gets hit by an arrow.

Any guidance you can provide will be appreciated.

cheers - shri

All 3 Comments
oranjoose

shri,

onOverlap certainly doesn't replace getOverlappingObjects()—indeed, the onOverlap event uses the getOverlappingObjects function to test for the overlap.

onOverlap on the other hand just makes checking for the moment of overlap a bit more intuitive.

Gio

That's right - onOverlap would just do, internally, the same thing that you are doing in an explicit way: every object that's got an onOverlap event calls getOverlappingObjects every frame to see if there's anything new that it is now overlapping. The event won't fire repeatedly - only when two objects start overlapping each other. If the objects are separated, and then overlap again, onOverlap will fire again.

So it comes down to personal preference. I agree that using onOverlap would be more intuitive as it results in less code and it's a bit tidier (in your scenario, you wouldn't have to keep an array of arrows and iterate over it) From a functional point of view it's pretty much the same thing though.

Shri

All,

Thanks for the info, I didn't bother to look at the code so I didn't know if something new was put in.

My apologies for not giving this post a title, I hit submit before I realized there wasn't one and then couldn't figure out a way to edit the title in the edit message screen.

cheers - shri

Post a reply
Add Attachment
Submit Reply
Login to Reply