2015-07-22 41 views
0

我是Andengine的初學者,所以我帶GLSE1練習我的第一個遊戲代碼。我試圖顯示一個啓動畫面,但它總是在「紋理」(不能實例化類型紋理)和「createFromAsset」中顯示錯誤。ANDENGINE Old [初始屏幕錯誤]

我對下面的啓動畫面的完整代碼:

package com.example.first.aq2; 

import org.anddev.andengine.engine.Engine; 
import org.anddev.andengine.engine.camera.Camera; 
import org.anddev.andengine.engine.options.EngineOptions; 
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation; 
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy; 
import org.anddev.andengine.entity.scene.Scene; 
import org.anddev.andengine.entity.sprite.Sprite; 
import org.anddev.andengine.entity.util.FPSLogger; 
import org.anddev.andengine.opengl.texture.Texture; 
import org.anddev.andengine.opengl.texture.TextureOptions; 
import org.anddev.andengine.opengl.texture.region.TextureRegion; 
import org.anddev.andengine.opengl.texture.region.TextureRegionFactory; 
import org.anddev.andengine.ui.activity.BaseGameActivity; 

public class AQ2 extends BaseGameActivity { 

    // =========================================================== 
    // Constants 
    // =========================================================== 
    private static final int CAMERA_WIDTH = 480; 
    private static final int CAMERA_HEIGHT = 320; 
    // =========================================================== 
    // Fields 
    // =========================================================== 
    private Camera mCamera; 
    private Texture mTexture; 
    private TextureRegion mSplashTextureRegion; 
    // =========================================================== 
    // Methods for/from SuperClass/Interfaces 
    // =========================================================== 
    @Override 
    public Engine onLoadEngine() { 
    this.mCamera = new Camera(0, 0, CAMERA_WIDTH,CAMERA_HEIGHT); 
    return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera)); 
    } 
    @Override 
    public void onLoadResources() { 
    this.mTexture = new Texture(512, 512,TextureOptions.BILINEAR_PREMULTIPLYALPHA); 
    this.mSplashTextureRegion = TextureRegionFactory.createFromAsset(this.mTexture,this, "gfx/Splashscreen.png", 0, 0); 
    this.mEngine.getTextureManager().loadTexture(this.mTexture); 
    } 
    @Override 
    public Scene onLoadScene() { 
    this.mEngine.registerUpdateHandler(new FPSLogger()); 
    final Scene scene = new Scene(1); 
    /* Center the splash on the camera. */ 
    final int centerX = (CAMERA_WIDTH - this.mSplashTextureRegion.getWidth())/2; 
    final int centerY = (CAMERA_HEIGHT - this.mSplashTextureRegion.getHeight())/2; 
    /* Create the sprite and add it to the scene. */ 
    final Sprite splash = new Sprite(centerX, centerY, this.mSplashTextureRegion); 
    scene.getLastChild().attachChild(splash); 
    return scene; 
    } 
    @Override 
    public void onLoadComplete() { 
    } 
    } 
    enter code here 

幫我做的第一步

+1

你說錯了什麼? – pskink

+0

在「紋理」(無法實例化紋理類型)中,行:this.mTexture = new Texture(512,512,TextureOptions.BILINEAR_PREMULTIPLYALPHA); –

回答

0

也許您正在使用尺寸大於紋理中提及的寬度和高度的圖像。檢查圖像的寬度和高度,嘗試增加紋理的寬度和高度,並檢查是否正常工作 OR 試試你的紋理改變BitmapTextureAtlas和嘗試這個

私人BitmapTextureAtlas mtexture; private TextureRegion mregion;

mtexture = new BitmapTextureAtlas(1024, 512, TextureOptions.BILINEAR_PREMULTIPLYALPHA);  
mregion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mtexture, getApplicationContext(), "Splashscreen.png",0,0); 
getEngine().getTextureManager().loadTexture(mtexture); 
0

首先,改變GLES2 - 中心定位,如果你還處於起步階段。

然後:

mTexture = new BitmapTextureAtlas(getTextureManager(), 256, 256, TextureOptions.DEFAULT); 
mSplashTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(yourTexture, this, "gfx/Splashscreen.png"", 0, 0); 
mTexture.load(); 

然後:

最終的Sprite飛濺=新的Sprite(的centerX,centerY,this.mSplashTextureRegion,mEngine.getVertexBufferObjectManager()); scene.getLastChild()。attachChild(splash);

  • 爲什麼你將它附加到最後一個子實體?