我正在做一个自上而下的视图游戏。实际上是一个非常简单的。当玩家在屏幕上点击时,角色会移动。但是,我也有一个开火按钮。我想知道当玩家按下按钮时如何禁用鼠标点击。因为当这种情况发生时,角色会移动到按钮位置。
这是我的代码:
var walk = false;
var goX = player.x;
var goY = player.y;
var speed = 10;
var dir = "down";
stage.addEventListener(Event.ENTER_FRAME, loop);
btn.addEventListener(MouseEvent.MOUSE_DOWN, btn1);
function btn1(event:MouseEvent):void
{
fireBullet();
}
function fireBullet():void {
var playerDirection:String;
if(player.scaleX < 0){
playerDirection = "left";
} else if(player.scaleX > 0){
playerDirection = "right";
}
if(char.scaleY < 0){
playerDirection = "up";
} else if(char.scaleY > 0){
playerDirection = "down";
}
var bullet:Bullet = new Bullet(player.x, player.y, playerDirection);
stage.addChild(bullet);
}
function loop(Event)
{
if (walk == true)
{
player.w.play();
}
else
{
player.w.gotoAndStop(1);
}
player.gotoAndStop(dir);
if ((goY-speed)>player.y)
{
player.y += speed;
dir = "down";
}
else if ((goY+speed)<player.y)
{
player.y -= speed;
dir = "up";
}
if ((goX-speed)>player.x)
{
player.x += speed;
dir = "right";
}
else if ((goX+speed)<player.x)
{
player.x -= speed;
dir = "left";
}
if ((goY-speed)>player.y || (goY+speed)<player.y || (goX-speed)>player.x || (goX+speed) <player.x){
walk = true;
} else {
walk =false
}
}
stage.addEventListener(MouseEvent.CLICK, set);
function set(MouseEvent){
goX=mouseX
goY=mouseY}
谢谢。