当使用ShapeRenderer,网+ SpriteBatch,Box2D的和Scene2D在Libgdx? [英] When to use ShapeRenderer, Mesh + SpriteBatch, Box2D and Scene2D in Libgdx?

查看:214
本文介绍了当使用ShapeRenderer,网+ SpriteBatch,Box2D的和Scene2D在Libgdx?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的安卓游戏开发后,我开始与libgdx ShapeRenderer,做了一点搜索,我变得困惑,如果我一开始用右脚。

I'm new in Android Game Development and after I started with libgdx ShapeRenderer and did a little more search, I became confused if I started with the right foot.

所以,我真正想知道的是,当我应该使用ShapeRenderer,网+ SpriteBatch,Box2D的和Scene2D。

So, what I really would like to know is when should I use ShapeRenderer, Mesh + SpriteBatch, Box2D and Scene2D.

推荐答案

LibGDX有相当多的(主要是正交)的API进行渲染。我还在学习我周围很多人的方式,但我可以给不同部分的概述。

LibGDX has quite a lot of (mostly orthogonal) APIs for rendering. I'm still learning my way around many of them, but I can give an overview of the different parts.

<一个href="http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/glutils/ShapeRenderer.html"相对=nofollow> ShapeRenderer 让你快速,轻松地把基本持平,带颜色的多边形和线条在屏幕上。它不是特别有效(它上传大量的顶点数据对每个渲染)。但它可以非常迅速地走了。它强烈地面向屏幕(默认为正交项目在整个屏幕上和它的单位一般是像素)。

ShapeRenderer lets you quickly and easily put basic flat-colored polygons and lines on the screen. Its not particularly efficient (it uploads a lot of vertex data on each render). But it can be very quick to get going. Its oriented strongly to the screen (it defaults to an orthographic project on the full screen and its units are generally pixels).

借助 类为您提供了更直接地控制几何,但你接触到了更多的细节(如编码颜色花车和存储顶点数据,颜色数据,和纹理数据的所有在同一个float数组,和数组索引的概念)。

The Mesh class gives you more direct control over geometry, but you're exposed to a lot more of the details (like encoding colors as floats and storing vertex data, color data, and texture data all in the same float array, and the concept of index arrays).

的<一个href="https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/SpriteBatch.html"相对=nofollow> SpriteBatch 是面向围绕精灵(在他们的纹理一般矩形区域)。这隐藏了一些与网格纹理的复杂性(和灵活性)。

The SpriteBatch is oriented around "sprites" (generally rectangular areas with a texture in them). This hides some of the complexity (and flexibility) of texturing with meshes.

Box2D的是物理模型,并且不喜欢任何你提到的其他API部分(基本都是关于渲染)的。

Box2D is for physics modeling, and is not like any of the other API parts you mentioned (which are mostly about rendering).

最后, Scene2D 主要是关于创建类似按钮的动画用户界面元素,列表和滑块。但它足够强大的(并且有足够的整洁和灵活的支持动画和交互事件),你可以在它实现了很多游戏了。

Finally, Scene2D is mostly about creating animated user-interface elements like buttons, lists, and sliders. But its powerful enough (and has enough neat and flexible support for animations and interaction events) that you can implement quite a lot of "game" in it too.

您也可以使用原始的OpenGL命令(见的 GL20 )了。

You can also use raw "OpenGL" commands (see GL20), too.

您完全可以混合和匹配这些不同的原语(一个需要注意的是,你通常必须刷新和结束无论 ShapeRenderer / SpriteBatch / 网​​渲染)。因此,举例来说,你可以使用Scene2D为你的主菜单,并在你的游戏中的一些元动作,一个 SpriteBatch 来使你的游戏的核心,并使用 ShapeRenderer 生成调试覆盖(觉得可视化边界框等)。

You can totally mix-and-match these different primitives (one caveat is that you generally must "flush" and "end" whatever ShapeRenderer/SpriteBatch/Mesh render before starting a different flavor). So, for example, you might use Scene2D for your "main menu" and some meta actions in your game, a SpriteBatch to render the core of your game, and use a ShapeRenderer to generate debug overlays (think visualizing bounding boxes, etc).

另外请注意,大多数libGDX的是着眼于2D。原的OpenGL 网​​的API也可以用于构建3D对象。

Also note that most of libGDX is geared towards 2D. Raw OpenGL and the Mesh APIs can also be used to build 3D objects.

检查 GDX-侵略者例如来看看它是如何使用,OpenGL和 SpriteBatch 。 (我觉得这个例子pre-日期Scene2d,所以有没有那...)。它也值得看看这些类的实现,看看他们在做什么在背后。

Check the gdx-invaders example to see how it uses Mesh, OpenGL, and SpriteBatch. (I think this example pre-dates Scene2d, so there is none of that...). Its also worthwhile to look over the implementation of these classes to see what they're doing underneath the covers.

这篇关于当使用ShapeRenderer,网+ SpriteBatch,Box2D的和Scene2D在Libgdx?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆