onEnterTile triggered when leaving tile

Post here your questions about the OpenSpace 2.x or notify bugs and suggestions.

Moderators: Lapo, Bax

User avatar
pozeat
Posts: 20
Joined: 04 Oct 2012, 13:53
Location: France
Contact:

onEnterTile triggered when leaving tile

Postby pozeat » 17 Oct 2012, 11:25

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
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: onEnterTile triggered when leaving tile

Postby Bax » 19 Oct 2012, 08:10

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.
Paolo Bax
The SmartFoxServer Team
User avatar
pozeat
Posts: 20
Joined: 04 Oct 2012, 13:53
Location: France
Contact:

Re: onEnterTile triggered when leaving tile

Postby pozeat » 26 Oct 2012, 11:57

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
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: onEnterTile triggered when leaving tile

Postby Bax » 26 Oct 2012, 12:54

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.
Paolo Bax
The SmartFoxServer Team
User avatar
pozeat
Posts: 20
Joined: 04 Oct 2012, 13:53
Location: France
Contact:

Re: onEnterTile triggered when leaving tile

Postby pozeat » 26 Oct 2012, 13:52

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
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: onEnterTile triggered when leaving tile

Postby Bax » 26 Oct 2012, 13:59

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?
Paolo Bax
The SmartFoxServer Team
User avatar
pozeat
Posts: 20
Joined: 04 Oct 2012, 13:53
Location: France
Contact:

Re: onEnterTile triggered when leaving tile

Postby pozeat » 26 Oct 2012, 14:28

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.
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: onEnterTile triggered when leaving tile

Postby Bax » 26 Oct 2012, 14:35

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).
Paolo Bax
The SmartFoxServer Team
User avatar
pozeat
Posts: 20
Joined: 04 Oct 2012, 13:53
Location: France
Contact:

Re: onEnterTile triggered when leaving tile

Postby pozeat » 26 Oct 2012, 14:43

Yes, I will use the tile coordinates.
Thank you for your fast replies.

Return to “OpenSpace v2 discussions and help”

Who is online

Users browsing this forum: No registered users and 14 guests