AndengineゲームアクティビティでネイティブTextView(表示)の使用方法
質問
私は知りたいですネイティブを使用する方法はありますか TextView
またはBaseandengine内のAndroidのその他のレイアウト Activity
.
私のアプリケーションは、画面全体の1つにAndengineを使用しています。この画面はBaseanDengineから拡張されており、その画面内のTextViewのようなネイティブビューを使用する必要があります。 Andengineはアラビア語のテキストではうまく機能しないため、ゲーム画面にアラビア語のテキストを表示する必要があります。
または、可能であれば、Andengineで変更可能なテキストでアラビア語のテキストを表示する方法。変更可能なテキストがアラビア語を左から右に逆に書くように。
解決
もちろんできます。
このコードを確認してください - 基本的にオーバーライドします onSetContentView
, 、それからあなたはあなたが望むものを何でも設定することができます。
@Override
protected void onSetContentView() {
final FrameLayout frameLayout = new FrameLayout(this);
final FrameLayout.LayoutParams frameLayoutLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT);
this.mRenderSurfaceView = new RenderSurfaceView(this);
mRenderSurfaceView.setRenderer(mEngine);
final FrameLayout.LayoutParams surfaceViewLayoutParams = new FrameLayout.LayoutParams(super.createSurfaceViewLayoutParams());
frameLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);
//Create any other views you want here, and add them to the frameLayout.
this.setContentView(frameLayout, frameLayoutLayoutParams);
}
(この方法はあなたのサブクラスに行きます BaseGameActivity
.)
XMLを介してそれを行うこともできますが、この方法はより明確だと思います。
他のヒント
アラビア語とペルシャ語のフォントにもAndengineを使用できます。しかし、別の方法で。そのためには、スプライトを作成し、ビットマップを追加する必要があります。その前に、そのビットマップにテキストを描画します。
次のコードは、ペルシャ/アラビア人のテキストを描き、スプライトに添付する例です。そのため、スプライトをシーンに取り付けることができます。これは、それがどのようにできるかを示す例です。そのため、ビットマップとテキストサイズを自分で調整できます。デバイスがペルシャ/アラビア人をサポートする場合、このコードは適切に機能します。テキストがシーンに表示されない場合、その位置を変更すると、画面外です
サンプルコード関数は、ペルシャ/アラビア人に「ペルシャゴルフ」を印刷します。
private void persianGolfPrinter(){
BitmapTextureAtlas mBitmapTextureAtlas = new BitmapTextureAtlas(ResourceManager.getInstance().gameActivity.getTextureManager(), 400, 800, TextureOptions.BILINEAR);
ITextureRegion mDecoratedBalloonTextureRegion;
final IBitmapTextureAtlasSource baseTextureSource = new EmptyBitmapTextureAtlasSource(400, 800);
final IBitmapTextureAtlasSource decoratedTextureAtlasSource = new BaseBitmapTextureAtlasSourceDecorator(baseTextureSource) {
@Override
protected void onDecorateBitmap(Canvas pCanvas) throws Exception {
this.mPaint.setColor(Color.BLACK);
this.mPaint.setStyle(Style.FILL);
this.mPaint.setTextSize(32f);
this.mPaint.setTextAlign(Align.CENTER);
pCanvas.drawText("خلیج فارس", 150, 150, this.mPaint);
}
@Override
public BaseBitmapTextureAtlasSourceDecorator deepCopy() {
throw new DeepCopyNotSupportedException();
}
};
mDecoratedBalloonTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromSource(mBitmapTextureAtlas, decoratedTextureAtlasSource, 0, 0);
mBitmapTextureAtlas.load();
Sprite test = new Sprite(0,0,mDecoratedBalloonTextureRegion,ResourceManager.getInstance().engine.getVertexBufferObjectManager());
this.attachChild(test);
}
Android TextViewを使用しないでください...それはあなたのゲームを醜くします....
AndengineのオブジェクトはOpenGLオブジェクトであるため、Andengineで直接使用することはできません。ただし、Android OSを使用して、標準ビューのビットマップを描画し、そのビューからテクスチャとスプライトを作成できます。これは、アラビア語のテキストなどのケースでは最適ではありませんが、機能します。ビューのビットマップを作成する際に、メモリリークに注意してください。