如何在Andengine游戏Activity中使用原生Textview(View)
我想知道是否有任何方法可以在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当然可以。
检查一下这段代码 - 基本上你覆盖
onSetContentView
,然后你可以设置任何你想要的。(这个方法会转到你的
BaseGameActivity
的子类。)你也可以通过xml来做到这一点,但我认为这个方法更清晰。
Of course you can.
Check this code out - basically you override
onSetContentView
, then you can set whatever you want.(This method goes to your subclass of
BaseGameActivity
.)You could also do it through xml, but I think this method is more clear.
您也可以将 Andengine 用于阿拉伯语和波斯语字体。但以不同的方式。为此,您需要创建一个 Sprite 并向其添加位图。在此之前,您可以在该位图上绘制文本。
以下代码是绘制波斯语/阿拉伯语文本并将其附加到精灵的示例。这样我们就可以将精灵附加到我们的场景中。
这是一个展示我们如何做到这一点的示例,因此您可以自己调整位图和文本大小。
如果您的设备支持波斯语/阿拉伯语,则此代码将正常工作。如果文本没有出现在您的场景中,请更改其位置,它位于屏幕之外,
示例代码函数将以波斯语/阿拉伯语打印“波斯高尔夫”。
不要使用 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.
don't use android textview... it makes your game ugly ....
你不能直接在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.