簡體   English   中英

ANDENGINE舊[啟動畫面錯誤]

[英]ANDENGINE Old [Splash Screen Error]

我是Andengine的初學者,因此我以GLSE1練習了我的第一個游戲代碼。 我試圖顯示一個初始屏幕,但它始終在“紋理”(無法實例化紋理類型)“ createFromAsset”中顯示錯誤。

我的初始屏幕完整代碼如下:

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

幫我做第一步

首先,如果您仍處於開始階段,請更改為GLES2-Anchor Center。

然后:

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

然后:

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

  • 為什么將它附加到最后一個子實體?

可能是您使用的圖像尺寸大於紋理中提到的寬度和高度。 檢查圖像的寬度和高度,然后嘗試增加紋理的寬度和高度,然后檢查其是否起作用,或者嘗試將紋理更改為BitmapTextureAtlas並嘗試執行此操作

私有BitmapTextureAtlas mtexture; 私有TextureRegion mregion;

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM