如何处理 flash/flex 中遮挡(重叠)显示对象上的鼠标事件?
我的问题与之前提出的有关重叠精灵/电影剪辑的一些问题有点相似,例如 这个。但我的要求和他们略有不同。
我想处理舞台上所有精灵的鼠标事件,包括隐藏在后面(或重叠或遮挡)的精灵,主要条件是我想处理被遮挡的精灵(隐藏在其他精灵后面)。例如,假设我在舞台上有 sprite1 和 sprite2,我想在每次单击 sprite 时开始拖动,并在再次单击后停止拖动。
这可以很容易地完成,但问题和我的主要要求是,如果我拖动 sprite1 并将其恰好放在 sprite2 的顶部,那么 sprite2 将隐藏在 sprite1 后面,如果不先移动 sprite1,我将无法拖动 sprite2 。如果你在facebook上玩过zynga的帝国和阿莱游戏,它是单独处理的,这就是游戏中的工作方式,鼠标事件在重叠精灵后面的精灵上触发,如果你有两个精灵与一个精灵重叠而不是鼠标事件在最后一个精灵上触发,而不是在前面的精灵上触发,无论是否只有一个精灵重叠,还是两个或三个,并且
如果任何一个可以的话 ,这种情况会发生在不规则形状的精灵(不仅仅是矩形)上请告诉我 zynga 如何实现这一点,或者帮助我找出如何实现它,这将是很大的帮助,
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种可能性是游戏没有监听每个单独精灵的点击事件。
在编写游戏时,您经常会实现网格系统。如果是这种情况,程序员就会记录所有精灵在网格上的放置位置。然后,程序员可以监听整个网格渲染器上的点击,并通过参考网格记录的鼠标位置来计算出选定的对象。
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.