0

我已经开始使用 ActionScript 编写代码,并尝试编写此程序。它会在舞台上绘制一个形状,您可以使用箭头键移动它。我添加了一个“边缘粘贴”功能,将一半的形状粘贴到边缘。这是我的代码:

function freemove(event:KeyboardEvent):void
{
    switch (event.keyCode)
    {
        case Keyboard.UP:
        {
            testing.y -= 5;
            if(testing.y < stage.width)
            {
                testing.y = 0;
                }
            break;
        }
        case Keyboard.DOWN:
        {
            testing.y += 5;
            // FOR BOTTOM EDGE.
            break;
        }
        case Keyboard.LEFT:
        {
            testing.x -= 5;
            if(testing.x < stage.height)
            {
                testing.x = 0;
                }
            break;
        }
        case Keyboard.RIGHT:
        {
            testing.x += 5;
            // FOR RIGHT EDGE.
            break;
        }
        }

    }

问题是:它只适用于左边缘和上边缘。我怎样才能使它适用于底部和右侧边缘?谢谢!=)

4

1 回答 1

2
// FOR BOTTOM EDGE.
if (shape.y + shape.height > stage.stageHeight)

// FOR RIGHT EDGE.
if (shape.x + shape.width > stage.stageWidth)

此外,您可能会混淆 LEFT 和 RIGHT 处理程序中的宽度和高度(为什么y要与宽度和x高度进行比较?)

于 2011-04-25T05:51:02.957 回答