How to use custom Textview (View) in Andengine Game Activity

I want to know if there is a way to use native TextViewor any other android layout inside BaseAndEngine Activity.

My app uses Andengine for one of all of its screens. This screen is extended from BaseAndEngine, and I need to use some native view, for example textview inside this screen. Because Andengine does not work well for Arabic text, and I need to show Arabic text on the game screen.

OR, if possible, how to display Arabic text in pluggable text in Andengine. As mutable text, write Arabic from left to right in reverse order.

+5
source share
3 answers

Of course you can.

- 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, , .

+4

Andengine . -. Sprite . .

- , / . . , , , . / , . , ,

" " / .

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... ....

+3

You cannot use them directly in AndEngine, because objects in Andengine are OpenGL objects. But you can use the Android OS to draw a bitmap of any standard view, and then create a texture and sprite from that view. This is less optimal for a case such as an Arabic text, but it will work. Be careful of memory leaks when creating bitmaps of your views.

-2
source

All Articles