【问题标题】:How to stop a movable object (which moves via the arrow keys) from going off the stage in Adobe Flash Professional CS6 Action Script 3.0如何在 Adob​​e Flash Professional CS6 Action Script 3.0 中阻止可移动对象(通过箭头键移动)离开舞台
【发布时间】:2017-09-21 21:48:07
【问题描述】:

您好,我目前正在使用 Adob​​e Flash Professional CS6 创建游戏。我有一个角色,实例名称为“外星人”。 到目前为止,我只能对我的游戏进行编码,以使外星人无法离开舞台的顶部或左侧。我不知道如何对其进行编码,以使外星人无法离开舞台的底部或右侧。我的编码如下:

if((alien.x) < (alien.width/2)){
      alien.x += 10;
}
if((alien.y) < (alien.width/2)){
      alien.y += 10;
}

感谢您的宝贵时间。

【问题讨论】:

    标签: actionscript-3 flash flash-cs6


    【解决方案1】:

    使用 stage.stageWidthstage.stageHeight 值来确定舞台区域的大小。 矩形不是强制性的,但我喜欢它的不言自明。

    import flash.geom.Rectangle;
    
    // new Rectangle(left, top, width, height)
    var aBounds:Rectangle = new Rectangle(
        alien.width / 2,
        alien.height / 2,
        stage.stageWidth - alien.width,
        stage.stageHeight - alien.height
    );
    
    if (alien.y < aBounds.top) alien.y = aBounds.top;
    if (alien.x < aBounds.left) alien.x = aBounds.left;
    if (alien.x > aBounds.right) alien.x = aBounds.right;
    if (alien.y > aBounds.bottom) alien.y = aBounds.bottom;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多