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

查看:21
本文介绍了如何在 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天全站免登陆