我正在尝试创建一个简单的游戏,船只通过键在左右之间移动。移动是好的,但是当我尝试检测左边的右端时它根本不起作用。以下是代码的一部分。可能有什么不对?
stage.addEventListener(Event.ENTER_FRAME,moveBoat);
function moveBoat(event:Event):void {
if(! boat.x >= 700){
if(moveLeft) {
boat.x -= 5;
boat.scaleX = 1;
}
if (moveRight) {
boat.x += 5;
boat.scaleX = -1;
}
}
}
答案 0 :(得分:0)
如果你已经解决了碰撞问题,那么这就是你投掷炸弹问题的答案。通过拥有5个布尔变量来实现它将是一种相当复杂的方法;相反,只需使用一个整数来记录你的船只有多少炸弹掉落,每次掉落一个,将这个值减少1.以下是一些示例代码:
//Create a variable to hold the number of bombs left.
var bombsLeft:int = 5;
//Create an event listener to listen for mouse clicks; upon a click, we'll drop a bomb.
addEventListener(MouseEvent.CLICK, dropBomb);
//The function dropBomb:
function dropBomb(event:MouseEvent):void
{
if (bombsLeft > 0)
{
//Create a new instance of the Bomb class; this could be an object in your Library (if you're using the Flash IDE), which has a graphic inside it of a bomb.
var newBomb:Bomb = new Bomb();
//Position the bomb.
newBomb.x = boat.x;
newBomb.y = boat.y;
//Add it to the stage
addChild(newBomb);
//Reduce the number of bombs you have left.
bombsLeft--;
}
//At this point you could check if bombsLeft is equal to zero, and maybe increase it again to some other value.
}
这不包括向下移动炸弹的代码,但你可以相当简单地使用更新循环。如果你正在努力做到这一点,请告诉我,我会给你另一个例子。
希望有所帮助。
得不