0

我是andengine的新手。我正在尝试在屏幕中实现游戏控制器图像。我正在关注 andengine 示例。但图像被破坏并以三角形的形状出现在屏幕的角落。请帮忙。我的代码如下............

public class ExtremeGame extends SimpleBaseGameActivity {

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

private Camera mCamera;

private BitmapTextureAtlas mBitmapTextureAtlas;
private TextureRegion mFaceTextureRegion;

private BitmapTextureAtlas mOnScreenControlTexture;
private TextureRegion mOnScreenControlBaseTextureRegion;
private TextureRegion mOnScreenControlKnobTextureRegion;

private DigitalOnScreenControl mDigitalOnScreenControl;

@Override
public EngineOptions onCreateEngineOptions() {
    this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
    return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera);
}

@Override
protected void onCreateResources() {
     BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");

     this.mBitmapTextureAtlas = new BitmapTextureAtlas(null, 32, 32, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
     this.mFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "face_box.png", 0, 0);

     this.mOnScreenControlTexture = new BitmapTextureAtlas(null, 256, 128, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
     this.mOnScreenControlBaseTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mOnScreenControlTexture, this, "onscreen_control_base.png", 0, 0);
     this.mOnScreenControlKnobTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mOnScreenControlTexture, this, "onscreen_control_knob.png", 128, 0);

     this.mEngine.getTextureManager().loadTexture(mOnScreenControlTexture);


}

@Override
protected Scene onCreateScene() {
    this.mEngine.registerUpdateHandler(new FPSLogger());

    final Scene scene = new Scene();

    final int centerX = (int) ((CAMERA_WIDTH - this.mFaceTextureRegion.getWidth()) / 2);
    final int centerY = (int) ((CAMERA_HEIGHT - this.mFaceTextureRegion.getHeight()) / 2);
    final Sprite face = new Sprite(centerX, centerY, mFaceTextureRegion, getVertexBufferObjectManager());
    final PhysicsHandler physicsHandler = new PhysicsHandler(face);
    face.registerUpdateHandler(physicsHandler);

    scene.attachChild(face);


    this.mDigitalOnScreenControl.getControlBase().setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    this.mDigitalOnScreenControl.getControlBase().setAlpha(0.5f);
    this.mDigitalOnScreenControl.getControlBase().setScaleCenter(0, 128);
    this.mDigitalOnScreenControl.getControlBase().setScale(1.25f);
    this.mDigitalOnScreenControl.getControlKnob().setScale(1.25f);
    this.mDigitalOnScreenControl.refreshControlKnobPosition();

    scene.setChildScene(this.mDigitalOnScreenControl);

    return scene;
}



 }
4

1 回答 1

2

这完全取决于您使用的是什么andengine 分支,gles2 或gles2 Anchor Center。

GLES2 Anchor Center 的主要、最显着的变化是坐标系发生了变化。GLES2 Anchor Center 分支中的坐标系原点位于左下方,由于多种原因已更改。

要了解新坐标系的工作原理,请参阅我的博客上发布的文章。

http://www.matim-dev.com/gles2-anchor-center.html

于 2013-08-29T23:28:23.103 回答