Skip to main content
Home Forums Silverlight Programming Programming with .NET - General MouseLeave and multiple layers
5 replies. Latest Post by Higgorama on October 26, 2008.
(1)
MartJ
Member
12 points
9 Posts
06-29-2007 4:49 PM |
I'm programming an isometric game with mulitple layers. Everything went fine, but now I ran into a problem which I cannot solve.
The game uses a series of tiles. Every tile has a base background (grass). Every tile also has an MouseEnter event, and when it is fired a structure is added to the canvas and drawn on top of the tile. The structure is a building with a lot of transparant background, it's bigger then the base tile and covers the base tile completely. When the MouseLeave occurs, the structure is removed from the canvas.
Well, problem now is when I Hover over the structure, the MouseLeave event of the base tile is fired. Even though the mouse actually is still on the right base tile. Somehow, MouseLeave is triggered when something with a bigger ZIndex is on top of the base tile. The result is a flickering graphical element.
I Tried some solutions like setting booleans when the relevant structure gets MouseEnter or MouseLeave and this works for most work but there are some exceptions. I don't understand why I can't get the position of the mouse with MouseEventArgs when the MouseLeave event is fired. That would solve it I guess. I tried using the MouseMove of the canvas and setting a point Property but this makes everything very slow.
Please can someone post a workaround/solution. I'm pretty stuck here
swildermuth
Star
8320 points
1,546 Posts
07-01-2007 3:42 AM |
Canvas.ZOrder was added later in the development cycle, if you use the natural order instead of Canvas.ZOrder, does it get better? (If you're already doing that, could you provide a simple example of what you mean?)
07-01-2007 9:12 AM |
I already draw in the natural order, the problem exists somehwhere else.
Imagine two rectangles like this
Now, when there is an MouseLeave event attached to the green rectangle, the event will also be fired when I hover over the blue rectangle, even when it is the part where the blue rectangle is on top the green rectangle. This is a simple representation of my problem. I cannot solve it by changing the drawing order because then the green layer will seem on top of the blue layer (like in there is grass on top of a building in my project :P)
Psychlis...
Contributor
6040 points
973 Posts
07-01-2007 1:11 PM |
Your overlaying piece gets in between the mouse and your underlying tile. If you hook the MouseEnter on your building, you'll very likely see it fire right when you get the mouse leave on your tile.
If you set the IsHitTestVisible to false on your building, does that take care of the issue with the tile?
Pete
07-01-2007 1:32 PM |
IsHitTestVisible was precisely the thing I was looking for, think I missed it in the documentation
Thnx
Higgorama
5 points
5 Posts
10-26-2008 9:29 AM |
This helped me as well - thank you for the answer!