如何在多个框架上隐藏鼠标?

时间:2015-05-24 15:27:43

标签: actionscript-3 mouseevent

我是一个动作脚本n00b,请原谅我的无知。 目前正试图制作我的第一人称射击游戏,并从Lynda(.com)中获取了很多技巧,但我很难将我的鼠标变成十字光标,并且在我创建此游戏时,这个十字准线在后续帧中不会永久显示。 / p>

所以我在动作图层上有这个代码,但在其他图层上创建另一个关键帧以更改我在其他图层上拍摄的内容时,我的光标会将自身的永久图像标记在屏幕上。如果我要擅长这种语言,我肯定需要更多地理解这种语言但是现在我喜欢能够制作一些游戏来娱乐自己,有什么建议吗?非常感谢

var cursor:MovieClip;

function initializeGame():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;
}

initializeGame();

1 个答案:

答案 0 :(得分:0)

在AS3中,项目将保留在显示列表中(在屏幕上),直到明确删除(或删除其父项)。

因此,为了防止光标停留在屏幕上,您需要将其删除:

removeChild(cursor);

执行Mouse.show()不会影响屏幕上的任何显示对象。

如果为var cursor分配一个新值,它不会自动删除前一个对象 - 因为变量只是对象的引用。因此,如果在后续帧中创建新光标,则需要在为变量分配新光标之前删除现有光标:

if(cursor.parent)  removeChild(cursor); //if there is an object assigned to cursor, and it has a parent (which means it's on screen), then remove it before doing the below code
cursor = new Cursor();
addChild(cursor);