2017-06-12 73 views
0

我是Action Script 3的初學者,目前正在開發彈跳球的基本遊戲。遊戲運行完美,彈跳球,並通過鼠標點擊改變方向,以及它的顏色。但是,現在我想進行一些改變,比如遊戲進行中;我希望球的尺寸很小,當比賽進行時,球會擴大。我已經在下面分享了我的代碼,具體來說,我需要在這一點上做。有什麼建議麼?更改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; 
      } 
     } 
    } 

} 

}

回答

0

您需要添加幾行:以25球幀率

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

所以,每一幀的球會增長1%,因此將在4秒內翻倍,在8秒內翻倍,等等。