绘制形状如LibGDX纹理 [英] Drawing shapes as textures in LibGDX

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

问题描述

我在我的游戏创建菜单带有圆角和边框专门矩形。我能做到这一点与形状渲染器,但我不能混用形状渲染器和精灵配料。此刻我的决心似乎是使用大形状,巴新和缩放他们,但在大量的设备,这将产生模糊的角落。

I'm creating menus in my game specially rectangles with rounded corners and borders. I can do this with a shape renderer but I cannot mix shape renderer and sprite batcher. At the moment my resolution seems to be using large shapes as PNG's and scaling them BUT on a lot of devices this produces blurry corners.

我读过我的网格,着色器教程,使用精灵批次(并发症层和性能的影响)之后的形状呈现,9补丁(边界模糊的云,不能做到正确的梯度)

I've read my tutorials on Meshes, shaders, using the shape renderer after the sprite batch (complication layer and performance impact), 9-patch (Border goes blurry, can't do gradients properly)

在Android的它是相当简单的,我们只是在XML中定义的形状和它创建了一个很好清脆形状,例如:圆角的矩形带有边框和梯度

In android it was fairly simple, we just define the shape in XML and it creates a nice crisp shape example: rounded rect with a border and a gradient.

任何人都可以给我一些建议过于我怎么会去的创建一个圆角的矩形用渐变,preferably一些易于使用的实现,可以在一个可重用的类中使用。

Could anyone give me some advice as too how I would go about's creating a rounded rect with a gradient, preferably some easy to use implementation that could be used in a reusable class.

推荐答案

您可以绘制形状的像素映射中,然后创建从他们TextureRegions与SpriteBatch呈现。

You could draw your shapes to PixMaps, and then create TextureRegions from them for rendering with SpriteBatch.

该工具集是有点基本的,但可以绘制点,线,三角形,圆形,矩形,填充,或从另一像素图绘制的区域。

The tool-set is a little basic, but you can draw points, lines, triangles, circles, rectangles, fill, or draw areas from another PixMap.

您可以绘制一个圆角矩形,通过绘制两个重叠的矩形,并为每个角落一个圆圈。

You can draw a rounded rectangle, by drawing two overlapping rectangles and a circle for each corner.

PixMap myPixMap = new PixMap(desiredWidth, desiredHeight, pixmapFormat);
myPixMap.setColor(myColor);
myPixMap.fillRectangle(x, y, width, height);

TextureRegion myTextureRegion = new TextureRegion(new Texture(myPixMap));

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

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