Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this code just display black image when run apk doesn't display background image
Java
package com.example.testandengine;
import org.andengine.ui.activity.BaseGameActivity;
import org.andengine.ui.activity.SimpleBaseGameActivity;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.entity.scene.Scene;
import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.opengl.texture.ITexture;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.bitmap.BitmapTexture;
import org.andengine.util.adt.io.in.IInputStreamOpener;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.texture.region.TextureRegionFactory;
import org.andengine.entity.sprite.Sprite;

import java.io.*;

import android.app.Activity;
import android.os.Debug;
import android.util.Log;
public class MainActivity extends SimpleBaseGameActivity {
private static int CAMERA_WIDTH = 800;
private static int CAMERA_HEIGHT = 480;
final Camera cam = new Camera(0, 0, CAMERA_WIDTH,CAMERA_HEIGHT);
	@Override
	public EngineOptions onCreateEngineOptions() {
		// TODO Auto-generated method stub
		return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED ,new RatioResolutionPolicy(CAMERA_WIDTH,CAMERA_HEIGHT),cam);
		
	}

	@Override
	protected void onCreateResources() {
	try
	{
		BitmapTextureAtlas bg = new BitmapTextureAtlas(this.getTextureManager(), 23, 23,
				TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		ITexture tower = new BitmapTexture(this.getTextureManager(), new IInputStreamOpener() {
			
			@Override
			public InputStream open() throws IOException {
				return getAssets().open("gfx/tower.png");
				
			}
		});
		
		ITexture ring1 = new BitmapTexture(this.getTextureManager(), new IInputStreamOpener() {
			
			@Override
			public InputStream open() throws IOException {
				// TODO Auto-generated method stub
				return getAssets().open("gfx/ring1.png");
			}
		});
		ITexture ring2 = new BitmapTexture(this.getTextureManager(), new IInputStreamOpener() {
			
			@Override
			public InputStream open() throws IOException {
				// TODO Auto-generated method stub
				return getAssets().open("gfx/ring2.png");
			}
		});
		ITexture ring3 = new BitmapTexture(this.getTextureManager(),new IInputStreamOpener() {
			
			@Override
			public InputStream open() throws IOException {
				// TODO Auto-generated method stub
				return getAssets().open("gfx/ring3.png");
			}
		});
		bg.load();
		tower.load();
		ring1.load();
		ring2.load();
		ring3.load();
		//this.bgRegion    = TextureRegionFactory.extractFromTexture(bg);
		this.bgRegion =BitmapTextureAtlasTextureRegionFactory.createFromAsset(bg, this, "gfx/background.png",0,0); 
		this.toweregion  = TextureRegionFactory.extractFromTexture(tower);
		this.ring1region = TextureRegionFactory.extractFromTexture(ring1);
		this.ring2region = TextureRegionFactory.extractFromTexture(ring2);
		this.ring3region = TextureRegionFactory.extractFromTexture(ring3); 
		
	}

		catch(Exception ex)
		{
      		 
		}
	}

	@Override
	protected Scene onCreateScene() {
	   final Scene scene = new Scene();
	   Sprite bgsprite =  new Sprite(0, 0, this.bgRegion, getVertexBufferObjectManager());
	   Sprite tower = new Sprite(190, 63, this.toweregion, getVertexBufferObjectManager());
	   scene.attachChild(bgsprite);
	   scene.attachChild(tower);
		return scene;
	}
	
	private ITextureRegion bgRegion,toweregion,ring1region,ring2region,ring3region;

}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900