【问题标题】:What is wrong with this ANDEngine HUD?这个 ANDEngine HUD 有什么问题?
【发布时间】:2014-12-28 13:26:58
【问题描述】:

我正在尝试在 AndEngine 上制作 HUD,但是当我在下面编写此代码并运行模拟器时,模拟器上出现的只是黑屏和 HUD 图像崩溃。

这就是我要显示的, 这就是我的代码的显示方式。

这是我的代码 -

package com.example.andenginetester;


import org.andengine.engine.camera.Camera;
import org.andengine.engine.camera.hud.HUD;
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.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;


public class SpriteTester extends SimpleBaseGameActivity {

	public static final int CAMERA_WIDTH = 720;
	public static final int CAMERA_HEIGHT = 480;
	
	private HUD myHUD;
	
	private Sprite myHUDSprite;
	
	private BitmapTextureAtlas myAtlas;
	private TextureRegion myHUDImage;
	final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);	
	
	@Override
	public EngineOptions onCreateEngineOptions() {


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


	@Override
	protected void onCreateResources() {
		myAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024);
		myHUDImage = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.myAtlas, this, "gfx/HUD.png", 0, 0);
		mEngine.getTextureManager().loadTexture(myAtlas);
		
	}

	@Override
	protected Scene onCreateScene() {
		final Scene scene = new Scene();
		scene.setBackground(new Background(0, 0, 0));
		myHUDSprite = new Sprite(0, 0, myHUDImage, this.getVertexBufferObjectManager());
		
		myHUD.attachChild(myHUDSprite);
		camera.setHUD(myHUD);
		return scene;

	}
	

	
	

}

我应该如何解决它?

【问题讨论】:

  • 可以分享一下图片/错误吗?
  • @ranifisch 我想分享,但它需要 10 个声望....
  • 顺便说一句,你试过在你的真实设备上工作吗?
  • @ranifisch 在 Galaxy Note 中也是如此。我刚试过
  • 您使用的是什么版本的 AndEngine?您的 HUD 初始化在哪里?

标签: andengine hud


【解决方案1】:

好吧,我设法得到了正确的结果,如果它适合你,请告诉我:

a) 我更新了 AndroidManifest.xml

添加在<activity ... >:

1)android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|mcc|mnc"

2)android:screenOrientation="landscape"

b) 更新的活动:

public class MainActivity extends SimpleBaseGameActivity {

    public static final int CAMERA_WIDTH = 720;
    public static final int CAMERA_HEIGHT = 480;

    private HUD myHUD = new HUD();

    private Sprite myHUDSprite;

    private BitmapTextureAtlas myAtlas;
    private TextureRegion myHUDImage;
    final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

    @Override
    public EngineOptions onCreateEngineOptions() {

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

    @Override
    protected void onCreateResources() {
        myAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024);
        myHUDImage = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
                this.myAtlas, this, "gfx/HUD.png", 0, 0);
        mEngine.getTextureManager().loadTexture(myAtlas);

    }

    @Override
    protected Scene onCreateScene() {
        final Scene scene = new Scene();
        scene.setBackground(new Background(0, 0, 0));
        myHUDSprite = new Sprite(0, 0, myHUDImage,
                this.getVertexBufferObjectManager());

        myHUD.attachChild(myHUDSprite);
        myHUD.setPosition(CAMERA_WIDTH/2,CAMERA_HEIGHT/2);
        camera.setHUD(myHUD);
        return scene;

    }

}

【讨论】:

  • 不幸的是,结果是一样的。
  • android:screenOrientation="landscape" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|mcc|mnc"
  • 奇怪..你只是得到一个黑屏? Logcat 说什么?
  • 11-04 23:58:53.391:E/AndEngine(6165):在 org.andengine.ui.activity.SimpleBaseGameActivity.onCreateResources(SimpleBaseGameActivity.java:43) 11-04 23:58: 53.391: E/AndEngine(6165): 在 org.andengine.ui.activity.BaseGameActivity.onCreateGame(BaseGameActivity.java:181) 11-04 23:58:53.391: E/AndEngine(6165): 在 org.andengine.ui .activity.BaseGameActivity.onSurfaceCreated(BaseGameActivity.java:110) 11-04 23:58:53.391: E/AndEngine(6165): at org.andengine.opengl.view.EngineRenderer.onSurfaceCreated(EngineRenderer.java:80)跨度>
  • 11-04 23:58:53.391: E/AndEngine(6165): 在 android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1494) 11-04 23:58:53.391: E/AndEngine(6165): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240) 这些都是错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-26
  • 2021-08-20
  • 2015-09-23
  • 2021-02-27
  • 2012-03-10
  • 2010-11-01
相关资源
最近更新 更多