图像未正确定位在发动机的屏幕中

时间:2013-08-27 12:29:58

标签: android andengine

是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;
}



 }

1 个答案:

答案 0 :(得分:2)

这完全取决于您使用的是什么动物分支,gles2或gles2锚定中心。

GLES2锚点中心的主要,最重要的变化是坐标系已经改变。 GLES2 Anchor Center分支中的坐标系原点位于左下方,由于多种原因而改变了。

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

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