基于Angle游戏引擎相关的文档说明

来源:互联网 发布:网络歌曲我想静静 编辑:程序博客网 时间:2024/05/29 16:06


   Android上的游戏引擎中,Angle是其中之一,觉得其小巧玲珑,故下面对其进行简而概之的进行相关的说明。

 

/** *下面的飞机是继承精灵类 */class MyShip extends AngleSprite{AngleVector mDestination;//时刻控制飞机的位置float Speed; //对应的飞机的速度public MyShip(AngleSpriteLayout sprite){super(sprite);mPosition.set(160,240);//默认的初始的位置mDestination=new AngleVector(mPosition); Speed=200;}@Overridepublic void step(float secondsElapsed){      //不断的将当前的飞机的位置接近最终的目标的位置                               if ((int)mPosition.mX<(int)mDestination.mX)mPosition.mX+=Speed*secondsElapsed;if ((int)mPosition.mX>(int)mDestination.mX)mPosition.mX-=Speed*secondsElapsed;if ((int)mPosition.mY<(int)mDestination.mY)mPosition.mY+=Speed*secondsElapsed;if ((int)mPosition.mY>(int)mDestination.mY)mPosition.mY-=Speed*secondsElapsed;super.step(secondsElapsed);}}class MyShot extends AngleSprite        {            public MyShot(MyShip ship, AngleSpriteLayout layout)            {                super(layout);                //初始化子弹的位置                mPosition.set(ship.mPosition.mX, ship.mPosition.mY - 20);            }            @Override            public void step(float secondsElapsed)            {                //默认的速度是300                mPosition.mY -= 300 * secondsElapsed;                if (mPosition.mY < -10)                    mDie=true;                super.step(secondsElapsed);            }                    };public MyDemo(AngleActivity activity)        {            super(activity);                        //Create and insert two main object groups. One for the game field and other for the dashboard            //>Creamos e insertamos dos grupos de objetos principales. Uno para el campo de juego y otro para los marcadores            ogField=addObject(new AngleObject());            ogDashboard=addObject(new AngleObject());            //Create a tile bank and a tile map for the ground (see constructors)            //>Creamos un banco de tiles y un mapa para el suelo (mirar los constructores)            AngleTileBank tbGround = new AngleTileBank(mActivity.mGLSurfaceView,R.drawable.tilemap,4,4,32,32);            tmGround = new AngleTileMap(tbGround, 320, 480, 15, 100, false,false);            for (int t=0;t<tmGround.mColumnsCount*tmGround.mRowsCount;t++)                tmGround.mMap[t]=(int) (Math.random()*tbGround.mTilesCount);            // Put the bottom of the camera at the lowest part of the map            //>Ponemos la c醡ara en la parte m醩 baja del mapa            tmGround.mTop = tmGround.mRowsCount* tbGround.mTileHeight - tmGround.mHeight;            ogField.addObject(tmGround);            slShip = new AngleSpriteLayout(mActivity.mGLSurfaceView,64, 64, R.drawable.anglelogo, 0, 0, 128, 128);            slShot = new AngleSpriteLayout(mActivity.mGLSurfaceView,16, 16, R.drawable.anglelogo, 0, 0, 128, 128);            mShip = (MyShip)ogField.addObject(new MyShip(slShip));            mOtherShip = (MyShip)ogField.addObject(new MyShip(slShip));                        //The dashboard background            //>Fondo de los marcadores            AngleSpriteLayout slDash = new AngleSpriteLayout(mActivity.mGLSurfaceView, 320, 64, R.drawable.tilemap, 0, 32, 320, 64);            AngleSprite mDash=(AngleSprite)ogDashboard.addObject(new AngleSprite (slDash));            mDash.mPosition.set(160, 480-slDash.roHeight/2);            mDash.mAlpha=0.5f;            //Font and text            //>Fuente y texto            AngleFont fntCafe25 = new AngleFont(mActivity.mGLSurfaceView, 25, Typeface.createFromAsset(getAssets(),"cafe.ttf"), 222, 0, 0, 30, 200, 255, 255);            ogDashboard.addObject(new AngleString(fntCafe25,"I Like The 2D Game Development Very Much~~",160,440,AngleString.aCenter));        }

从上面来看 真个游戏引擎是比较简单的


但是游戏引擎简单,需要克服的问题存在的

就是 创建地图的时候才,从上面的代码中可以看出  是直接创建100行的地图  ,但是如果创建更多,在手机上吃不消的,故需要一种很好的缓存的策略。

原创粉丝点击