如何在Andengine游戏Activity中使用原生Textview(View)

发布于 2024-12-19 06:18:15 字数 307 浏览 0 评论 0原文

我想知道是否有任何方法可以在 BaseAndEngine Activity 中使用本机 TextView 或 Android 的任何其他布局。

我的应用程序正在将 Andengine 用于其整个屏幕之一。该屏幕是从 BaseAndEngine 扩展的,我需要在该屏幕内使用一些本机视图,例如文本视图。因为 Andengine 不能很好地处理阿拉伯文本,我需要在游戏屏幕上显示一些阿拉伯文本。

或者如果可能的话如何在 Andengine 中以可更改的文本显示阿拉伯文本。作为可变文本,以相反的顺序从左到右书写阿拉伯语。

I want to know is there any way to use native TextView or any other layout of android inside BaseAndEngine Activity.

My application is using Andengine for one of its whole screen. This screen is extended from BaseAndEngine and I need to use some native view like textview inside that screen. Because Andengine does not work fine for Arabic text and I need to show some Arabic text on gaming screen.

OR if possible how to show Arabic text in changeable text in Andengine. As changeable text write Arabic from left to right in reverse order.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深海少女心 2024-12-26 06:18:15

当然可以。

检查一下这段代码 - 基本上你覆盖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来做到这一点,但我认为这个方法更清晰。

Of course you can.

Check this code out - basically you override onSetContentView, then you can set whatever you want.

@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);
}

(This method goes to your subclass of BaseGameActivity.)

You could also do it through xml, but I think this method is more clear.

成熟的代价 2024-12-26 06:18:15

您也可以将 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 textview...它会让你的游戏变得丑陋...

You can use Andengine for Arabic and Persian fonts too. But in a different manner. to do that you need to create a Sprite and add a bitmap to it. before that you draw your text on that bitmap.

the following code is an example that draw the Persian/Arabians text and attach it to a sprite. so we can attach the sprite to our scene.
this is an example to show how we can do that, so you can adjust the bitmap and text size by yourself.
if your device support Persian/Arabians, this code will work properly. if the text does not appear in your scene, change its position, it is out of screen

the example code function will print the "Persian Golf" in Persian/Arabians.

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

don't use android textview... it makes your game ugly ....

爱的十字路口 2024-12-26 06:18:15

你不能直接在AndEngine中使用它们,因为Andengine中的对象是OpenGL对象。但是您可以使用 Android 操作系统绘制任何标准视图的位图,然后从该视图创建纹理和精灵。对于阿拉伯文本等情况来说,这并不是最佳选择,但它会起作用。创建视图的位图时要小心内存泄漏。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文