嗨,以下代码在我的游戏中滚动到屏幕的左边缘或右边缘时有效;然而,当滚动到“地图”的边缘时,当滚动到屏幕的右边缘或下边缘时,我能够看到地图边缘之外,即我看到的是空白,即舞台的颜色。然而,当滚动到地图的左边缘或上边缘时,我无法看到地图边缘之外的东西。
public function scroll_screen():void { //scrolling left, right, up, down
var stagePositionX:Number = container.x+player.x;
var rightEdge:Number = stage.stageWidth-edgeDistance;
var leftEdge:Number = edgeDistance;
var stagePositionY:Number = container.y+player.y;
var bottomEdge:Number = stage.stageHeight-edgeDistance;
var topEdge:Number = edgeDistance;
//horizontal scrolling
if (stagePositionX > rightEdge) {
container.x -= (stagePositionX-rightEdge);
if (container.x < -(container.width-stage.stageWidth)) container.x = -(container.width-stage.stageWidth);
}
if (stagePositionX < leftEdge) {
container.x += (leftEdge-stagePositionX);
if (container.x > 0 )container.x = 0;
}
//vertical scrolling
if (stagePositionY > bottomEdge) {
container.y -= (stagePositionY-bottomEdge);
if (container.y < -(container.height-stage.stageHeight)) container.y = -(container.height-stage.stageHeight);
}
if (stagePositionY < topEdge) {
container.y += (topEdge-stagePositionY);
if (container.y > 0) container.y = 0;
}
}
希望这是有道理的,谢谢