1

我是AS3的初学者。我想在 400*450 的画布有限的空间中创建一个简单的弹跳球。但是当我发布它时它无法工作。任何人都可以帮我解决这个问题吗?PS:有什么好的网站可以帮助我了解更多关于AS3的东西吗?

这是我的代码:

function ballmoving(evt:Event = null):void 
{
    var vel_x = 5;
    var vel_y = 6;
    ball.x = -20;
    ball.y = 280;

    ball.x += vel_x;
    ball.y += vel_y;    
    if (ball.x > stage.stageWidth - ball.width / 2 || ball.x < 0 + ball.width /2)
    {
        vel_x *= -1;
    }
    else if (ball.y > 280 || ball.y < 0 + ball.height /2)
    {
        vel_y *= -1;
    }
}

ballmoving();

RecycleButton.addEventListener(MouseEvent.CLICK, reset);

function reset(event:MouseEvent):void
{
    ball.x = -20;
    ball.y = 280;
    ballmoving();
}
4

1 回答 1

3

尝试类似:

var vel_x = 5;
var vel_y = 6;

function ballmoving(evt:Event = null):void 
{

    ball.x += vel_x;
    ball.y += vel_y;    
    if (ball.x > stage.stageWidth - ball.width / 2 || ball.x < ball.width /2)
    {
        vel_x *= -1;
    }

    if (ball.y > 280 || ball.y < ball.height /2)
    {
        vel_y *= -1;
    }
}

stage.addEventListener(Event.ENTER_FRAME, ballmoving);
RecycleButton.addEventListener(MouseEvent.CLICK, reset);

function reset(event:MouseEvent):void
{
    ball.x = -20;
    ball.y = 280;
}
于 2013-03-14T17:57:36.393 回答