我正在制作一个使用鼠标进行碰撞检测的游戏。
[播放器是自定义鼠标光标,当鼠标与对象碰撞时,鼠标移动到坐标X0,Y0。我用来实现此目的的代码如下。但是,当鼠标在发生碰撞后移动到X0,Y0时,它将从发生碰撞的位置开始而不是从屏幕顶部移动。
import flash.events.Event;
var cursor:MovieClip;
function initializeMovie ():void {
cursor = new Cursor();
addChild (cursor);
cursor.enabled = false;
Mouse.hide ();
stage.addEventListener (MouseEvent.MOUSE_MOVE, dragCursor);
}
function dragCursor (event:MouseEvent):void{
cursor.x = this.mouseX;
cursor.y = this.mouseY;
}
initializeMovie ();
this.addEventListener( Event.ENTER_FRAME, handleCollision)
function handleCollision( e:Event ):void{
if(cursor.hitTestObject( wall )){
cursor.x = 0
cursor.y = 0
}
}
在0,0坐标处创建一个按钮,单击该按钮才能再次继续。然后,您的用户将不得不将鼠标移至该位置,您可以继续让自定义光标跟踪鼠标。
当重置光标对象的位置时,您并没有移动鼠标的实际位置,我不相信您可以实际执行您要执行的操作(即,写入鼠标位置以移动用户光标,我相信这将需要系统特定的代码,例如C#或我认为在Mac方面需要Objective C和Cocoa或Carbon。]
http://www.kirupa.com/forum/showthread.php?354641-Possible-to-set-mouse-position-in-flash
显然,这是您在Mac上可以使用的一种方法https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/Quartz_Services_Ref/Reference/reference.html#//apple_ref/c/func/CGWarpMouseCursorPosition
以及Windows上的一种方法Set Mouseposition in WPF
以及一种在Linux上的方法(尽管此方法仅对AIR的支持最高为2.6)How to set the mouse position under X11 (linux desktop)?
因此,如果您既实现了这两个解决方案,又将其打包为AIR应用程序,则可以完成这项工作,但否则我很确定这是不可能的。
gang gang gnag gang gnag gang gang gagn gang ggagaggagag