Gornova / MarteEngine

MarteEngine is a Java Engine for videogames
http://randomtower.blogspot.com
Other
74 stars 20 forks source link

leftWorldBoundaries called multiple times when entity leaves the world. #67

Closed Stef569 closed 12 years ago

Stef569 commented 13 years ago

Is it by design that the leftWorldBoundaries is called multiple times on leaving the world? I would expect that it is invoked once.

In World update: for (Entity e : entities) { e.updateAlarms(delta); if (e.active) e.update(container, delta); // check for wrapping or out of world entities e.checkWorldBoundaries(); }

in Entity The javadoc says 'act on leaving'. That sounds like a single event? /* * Overload if you want to act on leaving world boundaries / public void leftWorldBoundaries() { }

thaaks commented 13 years ago

Hi Stefan, I would say it's not by design but by code ;-) The behavior that it can be called multiple times in one update is definitely wrong (for example if x > width AND y > height it is triggered twice).

Additionally I would indeed tend to say that leftWorldBoundaries() only triggers once at all but obviously we haven't discussed this yet. Right now it would trigger as long as the entity is active but outside the world boundaries.

So if Gornova doesn't disagree I would modify the code to trigger leftWorldBoundaries() only once as long as it stays outside the world boundaries.

Question rises: do we want to trigger again if entity enters the world boundaries again or for the first time?

Gornova commented 12 years ago

My idea is to assure every entity in one update must exit or enter left boundaries, make sense ?

thaaks commented 12 years ago

What happens if an entity is added to the world but outside the boundaries? Would leftWorldBoundaries() be triggered on it's first update or not?

And Gornova, we only have leftWorldBoundaries(). Should we add enteredWorldBoundaries()? I don't think it is required...

Gornova commented 12 years ago

If is outside of boundaries is not "left" now, so is okay (IMHO) if leftWorldBoundaries() is not called. enteredWordlBoundaries could be an idea, but not for now (I never had to use it, you ?)

thaaks commented 12 years ago

No, I think enteredWorldBoundaries() is not really required at all...

Stef569 commented 12 years ago

What happens if an entity is added to the world but outside the boundaries? Would leftWorldBoundaries() be triggered on it's first update or not?

That makes no sense. I still like to think of it as an event. The event(method call) is fired once when an entity leaves the world. Like to remove a bullet from the world when it is outside the world.

thaaks commented 12 years ago

Yes Stefan, that's how it will beimplemented.