移动开发|Android在AndEngine创建第一个程序

首先要在lib文件夹中添加andengine.jar

1 package com.hu.anden; 2 3 import org.anddev.andengine.engine.Engine; 4 import org.anddev.andengine.engine.camera.Camera; 5 import org.anddev.andengine.engine.options.EngineOptions; 6 import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation; 7 import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy; 8 import org.anddev.andengine.entity.scene.Scene; 9 import org.anddev.andengine.entity.sprite.Sprite; 10 import org.anddev.andengine.opengl.texture.TextureOptions; 11 import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas; 12 import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory; 13 import org.anddev.andengine.opengl.texture.region.TextureRegion; 14 import org.anddev.andengine.ui.activity.BaseGameActivity; 15 16 public class MainActivity extends BaseGameActivity { 17 18public static int CAMERA_WIDTH = 320; 19public static int CAMERA_HEIGHT = 480; 20 21public Camera mCamera; 22public Scene mScene; 23private BitmapTextureAtlas bgTexture; 24private TextureRegion background; 25 26public Engine onLoadEngine() { 27this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT); //创建相机 28return new Engine(new EngineOptions(true, ScreenOrientation.PORTRAIT, 29new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), 30this.mCamera)); 31} 32 33public void onLoadResources() { 34bgTexture = new BitmapTextureAtlas(1024, 1024, 35TextureOptions.BILINEAR_PREMULTIPLYALPHA); 36background = BitmapTextureAtlasTextureRegionFactory.createFromAsset(//从资产读取图片 37bgTexture, this, "colorful.png", 0, 0); 38this.getEngine().getTextureManager().loadTextures(bgTexture); 39} 40 41public Scene onLoadScene() { 42mScene = new Scene(); 43mScene.setTouchAreaBindingEnabled(true); 44return mScene; 45} 46 47public void onLoadComplete() { 48Sprite bgd = new Sprite(0, 0, background); 49mScene.attachChild(bgd); 50} 51 52 }


移动开发|Android在AndEngine创建第一个程序
文章图片


【移动开发|Android在AndEngine创建第一个程序】转载于:https://www.cnblogs.com/hzy3774/archive/2012/07/22/2604214.html

    推荐阅读