我是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 :(得分:0)
您需要添加几行:
private function frameHandler(e:Event):void
{
ball.scaleX += 0.01;
ball.scaleY = ball.scaleX;
因此,球的每一帧都会增长1%,因此在25帧的速度下,球将在4秒内变为两倍大,在8秒内变为两倍,依此类推。