简体   繁体   English

ANDENGINE旧[启动画面错误]

[英]ANDENGINE Old [Splash Screen Error]

I'm a beginner with Andengine, so I take GLSE1 to practise my first game code. 我是Andengine的初学者,因此我以GLSE1练习了我的第一个游戏代码。 I tried to display a splash screen, but it always show errors in "Texture"(cannot instantiate the type texture), "createFromAsset". 我试图显示一个初始屏幕,但它始终在“纹理”(无法实例化纹理类型)“ createFromAsset”中显示错误。

My complete code for the splash screen below: 我的初始屏幕完整代码如下:

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

help me to do the first step 帮我做第一步

First of all, change to GLES2 - Anchor Center if you are still at the beginning. 首先,如果您仍处于开始阶段,请更改为GLES2-Anchor Center。

Then: 然后:

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

then: 然后:

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

  • why do you attach it to last child entity? 为什么将它附加到最后一个子实体?

May be you are using the image with the size greater than the width and height mentioned in the texture. 可能是您使用的图像尺寸大于纹理中提到的宽度和高度。 Check the width and height of the image and Try increasing the width and height of the texture and check if it works OR Try change your texture to BitmapTextureAtlas and try this 检查图像的宽度和高度,然后尝试增加纹理的宽度和高度,然后检查其是否起作用,或者尝试将纹理更改为BitmapTextureAtlas并尝试执行此操作

private BitmapTextureAtlas mtexture; 私有BitmapTextureAtlas mtexture; private TextureRegion mregion; 私有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