Pregunta

I'm trying to understand sprites in andEngine. I wrote the below code to load a simple image "img"

package com.example.pxc;

import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.atlas.bitmap.BuildableBitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.source.IBitmapTextureAtlasSource;
import org.andengine.opengl.texture.atlas.buildable.builder.BlackPawnTextureAtlasBuilder;
import org.andengine.opengl.texture.atlas.buildable.builder.ITextureAtlasBuilder.TextureAtlasBuilderException;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.ui.activity.SimpleBaseGameActivity;

public class TestActivity extends SimpleBaseGameActivity {

    static final int CAMERA_WIDTH = 800;
    static final int CAMERA_HEIGHT = 480;
    BuildableBitmapTextureAtlas bbta;
    ITextureRegion msr;
    @Override
    public EngineOptions onCreateEngineOptions() {
        Camera mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
        return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED,
            new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
    }

    @Override
    protected void onCreateResources() {
        // TODO Auto-generated method stub
        BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
         bbta = new BuildableBitmapTextureAtlas(mEngine.getTextureManager(), 256, 256);  
        msr=BitmapTextureAtlasTextureRegionFactory.createFromAsset(bbta, this, "img.png");
        try{
        bbta.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 1, 1));
        bbta.load();

                } catch (TextureAtlasBuilderException e) {
                e.printStackTrace();
                }       
    }

    @Override
    protected Scene onCreateScene() {
        Scene scene = new Scene();
        Sprite mSprite = new Sprite(0, 0,
                msr, mEngine.getVertexBufferObjectManager());
        scene.attachChild(mSprite);
        return scene;
    }
}

The above code compiles without any errors. When i run the code, i get to see a black screen on the emulator instead of the image. Why this happens? and how can i resolve this problem?

¿Fue útil?

Solución

If you want to run on Emulator first you have to provide settings as shown in this link If you want effective one to get good fps then following link may help you

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top