首先要把andengine.jar复制到libs文件夹里
03 |
import org.anddev.andengine.engine.Engine; |
04 |
import org.anddev.andengine.engine.camera.Camera; |
05 |
import org.anddev.andengine.engine.options.EngineOptions; |
06 |
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation; |
07 |
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy; |
08 |
import org.anddev.andengine.entity.scene.Scene; |
09 |
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; |
16 |
public class MainActivity extends BaseGameActivity { |
18 |
public static int CAMERA_WIDTH = 320; |
19 |
public static int CAMERA_HEIGHT = 480; |
21 |
public Camera mCamera; |
23 |
private BitmapTextureAtlas bgTexture; |
24 |
private TextureRegion background; |
26 |
public Engine onLoadEngine() { |
27 |
this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);//创建相机 |
28 |
return new Engine(new EngineOptions(true, ScreenOrientation.PORTRAIT, |
29 |
new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), |
33 |
public void onLoadResources() { |
34 |
bgTexture = new BitmapTextureAtlas(1024, 1024, |
35 |
TextureOptions.BILINEAR_PREMULTIPLYALPHA); |
36 |
background = BitmapTextureAtlasTextureRegionFactory.createFromAsset(//从资产读取图片 |
37 |
bgTexture, this, "colorful.png", 0, 0); |
38 |
this.getEngine().getTextureManager().loadTextures(bgTexture); |
41 |
public Scene onLoadScene() { |
43 |
mScene.setTouchAreaBindingEnabled(true); |
47 |
public void onLoadComplete() { |
48 |
Sprite bgd = new Sprite(0, 0, background); |
49 |
mScene.attachChild(bgd); |