Page 1 of 1
onEnterTile triggered when leaving tile
Posted: 17 Oct 2012, 11:25
by pozeat
The onEnterTile function is triggered twice by the avatarEnter event.
I have an avatarEvent on a tile, if my avatar walk to stop on it, the event is triggered. This works as expected.
But when I leave this tile the event is triggered again... Is it a normal behavior ?
My openspace version is 2.0.4
Thanks
Re: onEnterTile triggered when leaving tile
Posted: 19 Oct 2012, 08:10
by Bax
No, not normal. Are you sure you are not registering to the onLeaveTile event?
Or maybe you are registering twice for the onEnterTile event?
We tested this using the provided example and it works as expected: events are fired only once.
Re: onEnterTile triggered when leaving tile
Posted: 26 Oct 2012, 11:57
by pozeat
Hi Bax,
To explain a little bit more, I extended the Avatar class and overrided the onMovementStart, onMovementStop, onEnterTile, onLeaveTile functions like this :
Code: Select all
override public function onMovementStart(tile:Tile, triggers:Array):void {
trace("onMovementStart( "+tile.name+" )");
}
override public function onMovementStop(tile:Tile, triggers:Array):void {
trace("onMovementStop( "+tile.name+" )");
}
override public function onEnterTile(tile:Tile, triggers:Array):void {
trace("onEnterTile( " + tile.name + ", " + triggers+" )" );
}
override public function onLeaveTile(tile:Tile, triggers:Array):void {
trace("onLeaveTile( "+tile.name+", "+triggers+" )");
}
the tile i start from is "tile0", I press the right arrow key once and In the output panel i have these traces :
[OpenSpace|INFO] Path from (12,9,0) to (12,5,0) coordinates received for avatar 4
onEnterTile( tile0, null )
onMovementStart( tile0 )
onLeaveTile( tile0, null )
onEnterTile( tile1, null )
[OpenSpace|INFO] Stop avatar command received for avatar 4; target coordinates: (12,8,0)
onEnterTile( tile1, null )
onMovementStop( tile1 )
NB : the events are triggered even if I didn't declare any event in OpenSpace Editor
Do you think I missed something or did wrong ?
Thank you
Re: onEnterTile triggered when leaving tile
Posted: 26 Oct 2012, 12:54
by Bax
I think this is what happens: you are sending a stop command while the avatar is moving, but when the command is received, the avatar already started to move towards the next tile. For this reason the engine must place the avatar back to the tile, thus the event fired.
I can't verify this immediately, but this should be the explanation.
In case having the same event triggered two times is a problem, you can check if the coordinates of the passed tile object changed.
Re: onEnterTile triggered when leaving tile
Posted: 26 Oct 2012, 13:52
by pozeat
Hi Bax,
Thanks for your fast answer.
Ok, I can use the tile's coordinates to check if the avatar is still on the same tile.
About the problem, I'm not sending any stop command, I just move the avatar from a tile to another, and before leaving the actual tile, the onEnterTile function is called inside the com.smartfoxserver.openspace.engine.model.avatar.Avatar
The problem is the onEnterTile (in bold) just before the onMovementStart
[OpenSpace|INFO] Path from (12,9,0) to (12,5,0) coordinates received for avatar 6
onEnterTile( tile0, null )
onMovementStart( tile0 )
[OpenSpace|INFO] Stop avatar command received for avatar 6; target coordinates: (12,8,0)
onEnterTile( tile1, null )
onMovementStop( tile1 )
Thanks you
Re: onEnterTile triggered when leaving tile
Posted: 26 Oct 2012, 13:59
by Bax
Is the avatar standing on tile0 when you hit the key to go to tile1? Or is it already moving along a different path?
Did you check the same case using the mouse?
Re: onEnterTile triggered when leaving tile
Posted: 26 Oct 2012, 14:28
by pozeat
Hi Bax,
Yes the avatar is standing on tile0, not moving. Then I press the right arrow key to go to the tile1 (the 2 tiles are alongside each other).
Now I tried with the mouse, here is the output :
[OpenSpace|INFO] Path from (12,9,0) to (12,8,0) coordinates received for avatar 7
onEnterTile( tile0, null )
onMovementStart( tile0 )
onLeaveTile( tile0, null )
onEnterTile( tile1, null )
onMovementStop( tile1 )
with the arrow key :
[OpenSpace|INFO] Path from (12,9,0) to (12,5,0) coordinates received for avatar 9
onEnterTile( tile0, null )
onMovementStart( tile0 )
[OpenSpace|INFO] Stop avatar command received for avatar 9; target coordinates: (12,8,0)
onEnterTile( tile1, null )
onMovementStop( tile1 )
The problem is the same with the both way to control the avatar.
Re: onEnterTile triggered when leaving tile
Posted: 26 Oct 2012, 14:35
by Bax
Ok, thank you for reporting. We will look into it as soon as possible.
In the meanwhile I suggest that you implement the workaround we discussed before (check the tile coordinates).
Re: onEnterTile triggered when leaving tile
Posted: 26 Oct 2012, 14:43
by pozeat
Yes, I will use the tile coordinates.
Thank you for your fast replies.