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 に答える