在 Action Script 3 游戏中更改对象的大小

Changing size of an object in Action Script 3 gaming

我是 Action Script 3 的初学者,目前正在开发一款基本的弹跳球游戏。游戏运行完美,球弹跳并通过单击鼠标改变方向及其颜色。但是,现在我想做一些改变,比如在游戏进行的时候;我希望球的尺寸很小,并且随着游戏的进行,球会膨胀。我在下面分享了我的代码,具体来说,我现在需要做什么。有什么建议吗?

package  {

import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;



public class Main extends MovieClip {
    private var ball:Ball = new Ball();
    private var ballSpeed, cf: int;
    private var isLeft, isUp, isLand: Boolean;

    public function Main() {
        // constructor code
        createBall();
        ballSpeed = 5;
        isLeft = false;
        isUp = false;
        isLand = true;
        cf = 1;
        stage.addEventListener(Event.ENTER_FRAME, frameHandler);
        stage.addEventListener(MouseEvent.CLICK, changeDirection);

    }

    private function changeDirection(m:MouseEvent){

        if(isLand){
            isLand = false;
        } else {
            isLand = true;
        }

        cf += 1;

        if (cf > ball.totalFrames){
            cf = 1;
        }
        ball.gotoAndStop(cf);
    }

    private function createBall(){
        ball.x = stage.stageWidth * .5;
        ball.y = stage.stageHeight * .5;
        addChild(ball);





    }




    private function frameHandler(e:Event){

    if(isLand){
            if((ball.x + ball.width * .5)  < stage.stageWidth && !isLeft) {
                ball.x += ballSpeed;
                }
            if((ball.x + ball.width * .5) >=stage.stageWidth) {
                isLeft = true;
            }
            if((ball.x - ball.height * .5) > 0 && isLeft) {
                ball.x -= ballSpeed;
            }
            if((ball.x - ball.width * .5) <= 0){
                    isLeft = false;
        }
    }
    if(!isLand){
            if((ball.y + ball.height * .5) < stage.stageHeight && !isUp){
            ball.y += ballSpeed;
            }
            if((ball.y + ball.height * .5) >= stage.stageHeight){
                isUp = true;
            }
            if((ball.y - ball.height * .5) > 0 && isUp){
                ball.y -= ballSpeed;
            }
            if((ball.y - ball.width * .5) <= 0){
                isUp = false;
            }
        }
    }

}

}

您需要添加几行:

private function frameHandler(e:Event):void
{
    ball.scaleX += 0.01;
    ball.scaleY = ball.scaleX;

因此,每帧球会增长 1%,所以在 25 的帧率下,球会在 4 秒内变大两倍,在 8 秒内变大三倍,依此类推。