在不同的框架中初始化代码(在actionscript文件中)

时间:2017-11-28 01:24:47

标签: actionscript-3 flash actionscript

如何使用init函数在不同的帧中初始化此游戏?我正在使用Actionscript 3.0。

希望你能帮助我。  下面是代码(代码在actionscript文件中):

package{
import flash.display.MovieClip;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event; //used for ENTER_FRAME event

public class Main extends MovieClip{

    //constants
    const gravity:Number = 1.5;            //gravity of the game
    const dist_btw_obstacles:Number = 300; //distance between two obstacles
    const ob_speed:Number = 8;             //speed of the obstacle
    const jump_force:Number = 15;          //force with which it jumps

    //variables
    var player:Player = new Player();      
    var lastob:Obstacle = new Obstacle();  //varible to store the last obstacle in the obstacle array
    var obstacles:Array = new Array();     //an array to store all the obstacles
    var yspeed:Number = 0;                 //A variable representing the vertical speed of the bird
    var score:Number = 0;                  //A variable representing the score

    public function Main(){
        init();
    }

    function init():void {
        //initialize all the variables
        player = new Player();
        lastob = new Obstacle();
        obstacles = new Array();
        yspeed = 0;
        score = 0;

        //add player to center of the stage the stage
        player.x = stage.stageWidth/2;
        player.y = stage.stageHeight/2;
        addChild(player);

0 个答案:

没有答案