2012-08-08 154 views
1

我正在制作一款使用鼠标碰撞检测的游戏。AS3碰撞检测鼠标移动

当鼠标与物体移动到坐标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 
    } 

} 

回答

1

在0,0坐标上创建一个按钮,点击以继续。然后,您的用户将不得不将鼠标移动到可以继续使用自定义光标跟踪鼠标的位置。

1

当您重置光标对象并没有移动的实际鼠标位置的位置,我不相信你可以做到实际你想要什么(即写入鼠标位置移动用户光标,我相信这需要系统特定的代码,比如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应用程序,你可以使这项工作,但否则我非常确定这是不可能的。

+0

因此,解决问题的最佳方法是不用移动鼠标,而是让用户在某个特定像素处“抓住”一个正方形并移动此物体,然后将此物体位置重置为(0,0) – 2012-08-08 08:12:31