I started using AndEngine for Android (link) and I must say, WOW! I'm impressed!
I will say this though...
With all due respect, as amazingly awesome and powerful as this library is it is extremely hindered by its lack of clear and easy to find documentation. It is like pulling teeth trying to figure this thing out! Oh well, if it was easy it wouldn't be fun right!?!??!
Anyway, one of the things I was trying to do was set a static background.
There is probably a better way of doing this but this worked for me.
The way I've done it is as follows...
Landscape mode
I have the camera width and height set at: 854x480
The .jpg image that I use as a background is 854x480
Note: because you need to use a texture that is a power of 2 I had to set the texture area at 1024x512. This didn't seem to affect it.....yet!
@Override
public void onLoadResources() {
// Create a texture to load our sprite into
this.mBackgroundTexture = new Texture(1024, 512, TextureOptions.DEFAULT);
// Create a region to load the image asset into
this.mBackgroundRegion = TextureRegionFactory.createFromAsset(this.mBackgroundTexture, this, "gfx/YOUR_IMAGE.JPG", 0, 0);
// Load the texture (with the region that holds the asset) into the engine
this.mEngine.getTextureManager().loadTexture(this.mBackgroundTexture);
}
@Override
public Scene onLoadScene() {
// Do scene work...
// Might not need this but I did it anyway...
this.setBackground(new ColorBackground(0, 0, 0, 1));
// Create sprite
this.mBackground = new Sprite(0, 0, this.mBackgroundRegion);
//Attach the sprite to the scene. I use getFirstChild() so that I can ensure that the background sprite is the "bottom" child
scene.getFirstChild().attachChild(this.mBackground);
// Do some other work maybe...
return scene;
}
I will write up a more thorough tutorial soon!
Hope this helps :)
Thank you very much :)
ReplyDeleteNice, but you can use something like this
ReplyDeletescene.setBackground(new SpriteBackground(new Sprite(0, 0,this.mBackgroungRegion)));