我想在libgdx的OpenGL Surface中发生的所有事情上显示一些自定义视图(例如带有阿拉伯语/亚洲文本的TextViews)(< - 我假设它是一个表面视图)。这可能吗?怎么样?
我的动机是我在现有代码中显示文本的成熟组件,我想继续使用它。
我之前使用过其他GLSurfaceViews和View层次结构。只是想知道如何在libgdx中完成此操作。性能并不重要因为libgdx中的“游戏”是一个简单的益智游戏,当显示文本视图时,游戏几乎暂停了。
答案 0 :(得分:8)
是的,你可以!关于在Libgdx中使用Admob的这个official guide可以帮助您显示自定义视图。虽然它专注于集成Admob广告,但您可以使用该机制在OpenGL Surface顶部创建和显示视图。例如,这就是你在Android游戏的表面视图上显示文本视图的方式:
@Override public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create the layout
RelativeLayout layout = new RelativeLayout(this);
// Do the stuff that initialize() would do for you
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
// Create the libgdx View
View gameView = initializeForView(new HelloWorld(this), false);
// Create and setup the TextView
TextView helloText = new TextView(this);
// Add the libgdx view
layout.addView(gameView);
// Add the TextView
RelativeLayout.LayoutParams textViewParams =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
textViewParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
textViewParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
layout.addView(helloText, textViewParams);
// Hook it all up
setContentView(layout);
}