[Wade_iso] delete object when it reaches cell
robert.irmler

Hi all,

I'm using the the Wade isometric plugin and have created some objects that move from one cell to another.

My question: Is there a clever way to delete an object when it reaches its destination cell?

When I use deleteObject()/deleteObjectByName() directly after moveObjectToCell() it obviously kills my object right away. So I could use a setTimeout-function but that seems not really practical.
The deleteObjectsInCell()-function looks right, but how to trigger it at the right time?

Hope anyone can help...

Best,
Robert

All 4 Comments
Gio

Hi Robert and welcome to the forums:)

The answer to your question depends on whether your objects are IsoCharacters (and therefore use the built-in pathfinding algorithm to move around), or normal iso objects that you move around in straight lines.

In the first case, your objects will receive an 'onDestinationReached' event when they get to their destination. In the second case, responding to an 'onMoveComplete' event will be enough.

myIsoObject.onMoveComplete = function(){    wade.iso.deleteObject(this);};
robert.irmler

Ok, maybe I should have thought about it a little longer...
Made my objects IsoCharacters, used goToObject() instead of moveObjectToCell() and responded to the onObjectReached event...works.

robert.irmler

:D Just in time! Thanks for your reply!
Although I already  found a solution by myself, I'll try that too...as it seems more elegant...

Gio

I just wanted to add something that seems relevant even if not directly related to your question - I just have to write these things somewhere so if people search for them they'll find them :)

 

IsoCharacters also receive onMoveComplete events - in fact, all SceneObjects (not just isometric ones) receive onMoveComplete events when they finish moving after calling sceneObject.moveTo(). But since IsoCharacters use pathfinding, to get from A to B they call moveTo several time (moveTo only allows you to move the object on a straight line). As a result, they get multiple onMoveComplete events, one for each segment of their path. Only when they reach their final destination an onDestinationReached event fires.

 

This happens after you move the IsoCharacters to a cell with isoCharacter.setDestination().

 

Using isoCharacter.goToObject() may also be a good idea if, well, you have an object to go to! The difference is that, if the object has collisions, the character won't go into the same cell as the object, but will pick the nearest cell that's next to the object.  When it gets there, it receives an onObjectReached event.

 

If you want, you can choose which of the cells next to the object you want the character to go to when calling isoCharacter.goToObject(). You can do this by setting an interactionOffset property in the isometric object data, when you call wade.iso.createObject().

 

This can be useful if, for example, you have a building and want your character to move to the door when the building is clicked, or if you have a chest and want the character to go to the front side of it to open it when it's clicked, and so on. The fact that it's in the isometric object data, and the fact that it's an offset relative to the position of the isometric object, implies that you can set this once and then create multiple instances of your building, chest and so on without having to worry about it.

Post a reply
Add Attachment
Submit Reply
Login to Reply