2013-08-27 22 views
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; 
} 



} 

回答

2

這一切都取決於您使用的引擎分支,gles2或gles2 Anchor Center。

GLES2錨中心的主要,最重要的變化是座標系已經改變。 GLES2錨定中心分支中的座標系原點在左下角,這是由於多種原因而改變的。

要了解新座標系如何工作,請參閱發佈在我的博客上的文章。

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

+0

感謝您的建議。 –