基本上,我已经做到了,我的游戏中的“玩家”不会超过舞台宽度(仅沿 x 轴移动),因此当它到达边缘时它就会停止。但是,我想这样做,如果播放器超过左侧的宽度,它将从右侧流入,反之亦然。这是我现在拥有的代码,它阻止了它离开舞台区域:
function movePlayer(e:Event):void {
player.x = stage.mouseX;
// Doesn't go off the right or left side.
if (player.x < 0) {
player.x = 0;
} else if (player.x > (stage.stageWidth - player.width)) {
player.x = stage.stageWidth - player.width;
}
}
有没有办法可以编辑这个?