2014-04-09 82 views
0

我想了解andEngine中的精灵。我写了下面的代码来加载一个简单的图像“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; 
    } 
} 

上面的代码编译没有任何错误。当我运行代码时,我看到模拟器上的黑色屏幕而不是图像。为什么会发生?我该如何解决这个问题?

+0

这可能是因为你的仿真器是不支持提供设置gles2.Look at my post it may help you – Rama

+0

img.png有多大?我怀疑你的TextureAtlas可能不够大以容纳图像。我认为如果问题是模拟器设置,它只会出错,不会显示黑屏。 – jmroyalty

回答

0

如果你想在模拟器中运行你首先如图this link 如果你想有效的一种,以获得良好的FPS然后按照link可以帮助你