2017-03-02 5 views
1

AndEngine GLES2로 게임을 만들고 있습니다. 활동에 이미지를로드하려고합니다. 하지만 매번 앱을 실행할 때마다 오류없이 작은 검은 색 사각형이 표시됩니다. 아래 코드는AndEngine은 오류없이 검은 색 화면을 표시합니다.

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.scene.background.Background; 
import org.andengine.entity.sprite.Sprite; 
import org.andengine.entity.util.FPSLogger; 
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas; 
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory; 
import org.andengine.opengl.texture.region.TextureRegion; 
import org.andengine.ui.activity.SimpleBaseGameActivity; 

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 

public class MainActivity extends SimpleBaseGameActivity { 




     private static final int CAMERA_WIDTH = 480; 
     private static final int CAMERA_HEIGHT = 640; 

     private BitmapTextureAtlas ourAtlas; 

     private TextureRegion ourCircle; 

     private Sprite circle; 

     @Override 
     public EngineOptions onCreateEngineOptions() { 
       final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT); 

       return new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR, 
new RatioResolutionPolicy(CAMERA_WIDTH,CAMERA_HEIGHT), camera); 
     } 

     @Override 
     protected void onCreateResources() { 


       ourAtlas = new BitmapTextureAtlas(this.getTextureManager(),256,512); 

       ourCircle = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.ourAtlas, 
this, "gfx/rectangle.png",0,0); 

     mEngine.getTextureManager().loadTexture(ourAtlas); 
     } 

     @Override 
     protected Scene onCreateScene() { 

       this.mEngine.registerUpdateHandler(new FPSLogger()); 


       final Scene mScene = new Scene(); 


       circle = new Sprite(32, 32, ourCircle, this.getVertexBufferObjectManager()); 
     mScene.attachChild(circle); 
       mScene.setBackground(new Background(1.0f,1.0f,1.0f)); 



       return mScene; 
     } 



} 

오류없이 완벽하게 실행됩니다. 그러나 스크린은 중간에 작은 검은 사각형을 보여줍니다. 나는 왜 이미지가 보이지 않는지 이해하지 못한다. 아래는 활동의 스크린 샷입니다. 사람이 무엇이 잘못되었는지를 살펴한다면

Click on this link to see the screenshot from my activity

나는 그것을 사랑 해요 것입니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

답변

0

해결책을 찾았습니다.

ourAtlas = new BitmapTextureAtlas(this.getTextureManager(),256,512); 

위의 줄에서는 1024,1024로 아틀라스의 너비와 높이를 변경해야하며 완벽하게 작동했습니다. 문제는 내 크기 였어.

0

이 같이 텍스처를로드하려고 :

public void onCreateResources() { 

    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/"); 


    this.mBuildableBitmapTextureAtlas = new BuildableBitmapTextureAtlas(this.getTextureManager(), 512, 512); 

    this.yourTexture = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBuildableBitmapTextureAtlas, this, "yourimage.png"); 


    try { 

     this.mBuildableBitmapTextureAtlas.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 0, 0)); 

     this.mBuildableBitmapTextureAtlas.load(); 

    } catch (TextureAtlasBuilderException e) { 

     Debug.e(e); 

    } 

} 

것은 또한 먼저 배경을 설정하려고하고 아이들을 첨부합니다.

관련 문제