سؤال

my questions is little similar to some of the questions asked previously about overlapped sprites/movieclips like this. But my requirement is slightly different than them.

I want to handle the mouseevents for all the sprites on the stage including the one those are hidden behind (or overlapped or occluded) and the main condition is that I want to handle the occluded sprite (that hidden behind other sprite). example, say I have sprite1 and sprite2 on stage and I want to start drag whenever i click on the sprite and stop drag after another click.

This can be done easily, but the problem and my main requirement is that if I drag the sprite1 and drop it exactly on top of the sprite2 then sprite2 will be hidden behind the sprite1 I wont be able to drag the sprite2 without moving the sprite1 first. if you have played zynga's empires and allais game on facebook, it is handled seperatly, it is how it works in that game, the mouse event is triggered on the sprite behind the overlapping sprite, if you have two sprites overlapping one sprite than the mouse event is triggered on the sprite which is last and not the one in front irrespective of whether there is only one sprite overlapping or two or three and this happens to irregular shaped sprites (not just rectangles)

if any one can give me hit on how zynga might have implemented this or help me find out how to achive it it will be great help

thanks

هل كانت مفيدة؟

المحلول

One possibility is that the game is not listening to the click events from each separate sprite.

When programming games, you often implement a grid system. If this is the case, the programmer has a record of where all sprites are placed on the grid. The programmer could then listen for a click on the entire grid renderer and work out the selected object by referencing the mouse position against the grid records.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top