LibGDX中的shapeRenderer绘制环 [英] Draw Ring with shapeRenderer in LibGDX

查看:223
本文介绍了LibGDX中的shapeRenderer绘制环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用shaperenderer画一个圆环(大边框的圆形).

I want to draw a ring (circle with big border) with the shaperenderer.

我尝试了两种不同的解决方案:

I tried two different solutions:

  1. 解决方案:绘制n个圆形,每个圆形的宽度为1像素,比以前的圆形大1像素.问题在于:它会产生图形故障. (也具有不同的多样本抗锯齿"值)

  1. Solution: draw n-circles, each with 1 pixel width and 1 pixel bigger than the one before. Problem with that: it produces a graphic glitch. (also with different Multisample Anti-Aliasing values)

解决方案:先画一个大的实心圆,然后再用backgroundcolor画一个较小的实心圆.问题:我无法实现重叠的环形.其他一切都很好.

Solution: draw one big filled circle and then draw a smaller one with the backgroundcolor. Problem: I can't realize overlapping ring shapes. Everything else works fine.

我不能使用环形纹理,因为必须增加/减小动态环形半径.边框宽度应始终具有相同的值.

I can't use a ring texture, because I have to increase/decrease the ring radius dynamic. The border-width should always have the same value.

如何使用shaperenderer绘制光滑的环?

How can I draw smooth rings with the shaperenderer?

增加线宽没有帮助:

Increasing the line-width doesn't help:

推荐答案

MeshBuilder可以选择使用ellipse方法创建环.它允许您指定环的内部和外部尺寸.通常,这将导致生成网格,您需要渲染自己.但是由于最近的更改,还可以与PolygonSpriteBatch结合使用(Batch的实现允许更灵活的形状,而SpriteBatch仅允许四边形).您可以使用PolygonSpriteBatch而不是通常使用SpriteBatch的位置(例如,对于StageSprite类).

MeshBuilder has the option to create a ring using the ellipse method. It allows you to specify the inner and outer size of the ring. Normally this would result in a Mesh, which you would need to render yourself. But because of a recent change it is also possible to use in conjunction with PolygonSpriteBatch (an implementation of Batch that allows more flexible shapes, while SpriteBatch only allows quads). You can use PolygonSpriteBatch instead of where you normally would use a SpriteBatch (e.g. for your Stage or Sprite class).

以下是使用方法的示例: https://gist.github.com/xoppa/2978633678fa1c19cc47 ,但请记住,您确实需要为此进行每晚更新(或至少是1.6.4版).

Here is an example how to use it: https://gist.github.com/xoppa/2978633678fa1c19cc47, but keep in mind that you do need the latest nightly (or at least release 1.6.4) for this.

这篇关于LibGDX中的shapeRenderer绘制环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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