如何在Libgdx中渲染圆形/径向进度条? [英] How to render a circular/radial progress bar in Libgdx?

查看:178
本文介绍了如何在Libgdx中渲染圆形/径向进度条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我们使用libgdx开发的游戏,我们需要向用户显示进行移动的剩余时间. 我们如何渲染显示剩余秒数的圆形进度条?

For a game we develop with libgdx, we need to show the user the remaining time for making a move. How can we render a circular progress bar which shows the remaining seconds?

在以下答案中,有一个javascript解决方案: 圆形/径向进度栏

In the following answer there is a javascript solution : Circular / radial progress bar

谢谢.

推荐答案

首先使用完整的圆形进度条创建一个纹理(区域).接下来,将由一个或多个三角形组成的形状(网格)变形,以适合应显示的实际区域.

First create a texture (region) with the full circular progress bar. Next deform a shape (mesh) made up of one or more triangles to fit the actual area which should be shown.

为此,请考虑一条从图像中心到图像边界的线.计算给定角度的直线的交点(和墙",即图像的左,右,上或下).这将为您提供需要绘制的纹理(区域)部分.

For this, think of a line from the center of the image to the bounds of the image. Calculate the intersection point (and "wall", i.e. left, right, top or bottom of the image) of the line at the given angle. This will give you the portion of the texture (region) that needs to be drawn.

例如,如果静止的线(角度为零)与图像的底壁在中间交叉,则您的图像为正方形,并且您想顺时针旋转,则45至135度之间的所有物体都将撞到左壁, 135度到225度之间会碰到顶壁,依此类推.

For example, if the line at rest (angle is zero) crosses the bottom wall of the image at the middle, your image is square and you want to rotate clockwise, then everything between 45 and 135 degrees hits the left wall, between 135 and 225 degrees hits the top wall, and so on.

现在有了形状,您需要将其表示为三角形.或者保持与libgdx的spritebatch(偶数个三角形)的兼容性.确保根据顶点位置更新U和V值.

Now you have the shape, you'll need to express it in triangle. Or to maintain compatibility with libgdx's spritebatch, an even number of triangles. Make sure to update the U and V values according to the location of the vertex.

可以在这里找到一个简单的实现: https://github.com/xoppa/world/blob/master/src/com/xoppa/android/misc/RadialSprite.java

A simple implementation of this can be found over here: https://github.com/xoppa/world/blob/master/src/com/xoppa/android/misc/RadialSprite.java

这篇关于如何在Libgdx中渲染圆形/径向进度条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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