如何使用 ActionScript 3 创建鼠标单击时的连续射击效果?
当有人“单击并按住”时,我想一遍又一遍地触发功能,例如,在单击鼠标时每 100 毫秒触发一次。我会查找 MouseEvent.MOUSE_DOWN,而不是 MouseEvent.CLICK,然后在该事件函数上启动一个计时器,每 100 毫秒调用另一个函数。然后,在 MouseEvent.MOUSE_UP 上我将停止计时器。我走在正确的轨道上吗?当 mousedown 事件触发时,我能否获得更新的 X 和 Y 坐标?
When someone "click and holds" I want to fire off function over and over, say, once every 100ms while the mouse is clicked. Instead of MouseEvent.CLICK I would look for MouseEvent.MOUSE_DOWN and then start a timer on that event function that calls another function every 100ms. Then, on MouseEvent.MOUSE_UP I would stop the timer. Am I on the right track? Will I be able to get updated X and Y coordinates while the mousedown event is firing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试类似的事情:就我个人而言,我不会有计时器,而只是让帧速率来处理事情发生的频率。
这是一个快速开火效果,仅供参考:)
Try something similar to this: Personally I wouldn't have a timer, and just let the framerate handle how often stuff happens.
Here's a quick fire effect just for kicks :)
你走在正确的轨道上。要在
MouseEvent.MOUSE_DOWN
上获取更新的鼠标坐标,请添加MouseEvent.MOUSE_MOVE
侦听器,并将 X 和 Y 坐标保存到此侦听器中的某个变量。因此,当调用“伪”点击侦听器时,您将始终拥有更新的坐标。并在MouseEvent.MOUSE_UP
上删除MouseEvent.MOUSE_MOVE
侦听器。或
您可以只使用
mouseX
、mouseY
和contentMouseX
、contentMouseY
(对于 Flex 中的 UIComponent) 组件的属性。You're on the right track. To get updated mouse coordinates also on
MouseEvent.MOUSE_DOWN
addMouseEvent.MOUSE_MOVE
listener and save X and Y coordinates to some variable in this listener. So when calling your "pseudo" click listener, you'll always have updated coordinates. And onMouseEvent.MOUSE_UP
removeMouseEvent.MOUSE_MOVE
listener.OR
You can just use
mouseX
,mouseY
, andcontentMouseX
,contentMouseY
(for UIComponent in Flex) properties of your component.将按钮的autorepeat 属性设置为true 后监听buttonDown 事件。
Listen for buttonDown event after setting autorepeat property of button to true.