Page 1 of 1

IgeTileMap2d mouse events fire before all others?

Posted: Thu Sep 26, 2013 4:43 pm
by foolmoron
So I've noticed that the mouse events for a TileMap2d (mouseDown, mouseUp, mouseMove) are fired during the TileMap2d's tick function, which is called during IgeEntity.renderSceneGraph. All other input events are fired through the IgeInputComponent's tick, which is called after all the render ticks. Is this intentional?

I'm getting two unwanted side-effects from this:
1. TileMap2d mouse events always occur, and are always first
2. I can't stop the propagation of input events from a TileMap2d mouse event handler

This makes it pretty annoying when I have a clickable button over a clickable tile map and I want the button to eat the mouse event. Or am I missing something and/or doing something wrong?

Re: IgeTileMap2d mouse events fire before all others?

Posted: Fri Sep 27, 2013 8:51 pm
by coolbloke1324
foolmoron wrote:So I've noticed that the mouse events for a TileMap2d (mouseDown, mouseUp, mouseMove) are fired during the TileMap2d's tick function, which is called during IgeEntity.renderSceneGraph. All other input events are fired through the IgeInputComponent's tick, which is called after all the render ticks. Is this intentional?

I'm getting two unwanted side-effects from this:
1. TileMap2d mouse events always occur, and are always first
2. I can't stop the propagation of input events from a TileMap2d mouse event handler

This makes it pretty annoying when I have a clickable button over a clickable tile map and I want the button to eat the mouse event. Or am I missing something and/or doing something wrong?
Hey ya,

Yes, tilemaps are TRICKY! The reason for the mouse events being handled directly by the map is that tilemaps are effectively infinite. They have no width or height or any real bounds at all. With this in mind, the engine is unable to detect if a mouse click was *inside* a map's axis-aligned bounding box because the box has no dimensions.

You can see the dilema... if you use standard entity mouse hit detection it requires a bounding box but the bounds are infinite. I guess there might be a way around that but I'm not sure.

Re: IgeTileMap2d mouse events fire before all others?

Posted: Sat Sep 28, 2013 4:37 pm
by foolmoron
Makes sense.

Although in my case, the clickable area of the tile map is bounded, so I guess I'll just use an auxiliary entity overlayed on top to handle the mouse events.

Edit: Just tried the above solution and it works beautifully. Mount an isometric entity to the tile map and set its bounds using size3d to whatever clickable bound you want (with a height of 0 so that it is sorted under all other mounted entities). Translate it so that it aligns properly with the tile map (because its default origin is in the center of the object). Then you can add whatever mouse events you want to the entity and it will behave as you would expect, using IgeInputComponent. You can still reference the parent tile map to use mouseToTile and other functions, so it's a pretty seamless interface.