绘制弧形自定义对象在LIBGDX? [英] Draw curved custom object in LIBGDX?

查看:192
本文介绍了绘制弧形自定义对象在LIBGDX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在寻找到LibGDX,似乎都碰了壁,在图片中看到,蓝点重新presents用户的手指,映射表生成它的自我是我似乎被卡住,不LibGDX提供动态绘制曲线对象的方法?我可以简单地生成它们自己的图像,但图像将被无限拉伸到了手指的缝隙处可容纳3!但也需要1000高大,以适应整体水平设计的PX的。

I've recently been looking into LibGDX and seem to have hit a wall, seen in the picture, the blue dot represents the users finger, the map generation it self is where i seem to get stuck, does LibGDX provide a method of dynamically drawing curved objects? I could simply generate them myself as images but then the image is hugely stretched to the point of the gap for the finger can fit 3! But also would need to be 1000's of PX tall to accommodate the whole level design.

是不是这样的,我要画上百个多边形并拢,使曲线?
在一个侧面不是我需要确定的方式,当物体从底部有顶部这样我就可以生成另一个地图的块。

Is it such that i should be drawing hundreds of polygons close together to make a curved line? On a side not i'll need a way of determining when the object has from bottom to top so i can generate another 'chunk' of map.

推荐答案

您不需要数以百计的多边形,使曲线就像你画。你可以逃脱左侧40辆四轮摩托车和40在右边,并且它看起来pretty流畅。提高了100个,每边,它会看起来几乎完美流畅,没有现代化的设备将有运行在60fps任何麻烦。

You don't need hundreds of polygons to make a curve like you drew. You could get away with 40 quads on the left, and 40 on the right, and it would look pretty smooth. Raise that to 100 on each side and it will look almost perfectly smooth, and no modern device is going to have any trouble running that at 60fps.

您可以使用网格类生成每边一个程序的网格。您可以使网格停留在一个地方,锁定到相机,并修改它的顶点和UV的,使它看起来像你平移下来一个无限长的走廊。这将需要数学相当数量的前面,但应该是一帆风顺的,一旦你有一个了。

You could use the Mesh class to generate a procedural mesh for each side. You can make the mesh stay in one spot, locked to the camera, and modify it's vertices and UVs to make it look like you are panning down an infinitely long corridor. This will take a fair amount of math up front but should be smooth sailing once you have that down.

基本上,你的设计水平可以基于某种公式是采用y为输入失调。或者,它可能是偏移的多头排列,你可以使用一个样条曲线方程或线性方程它们之间进行插补。输出将是紫外线和X坐标,可用于更新每个两个网格的顶点

Basically, your level design could be based on some kind of equation that takes Y offset as an input. Or it could be a long array of offsets, and you could use a spline equation or linear equation to interpolate between them. The output would be the UV and X coordinates which can be used to update each of the vertices of your two meshes.

您可以使用顶点着色器有效地更新了UV坐标,通过不断弥补您更新每一帧均匀参数。这样,你就不必UV数据每帧移动到GPU。

You can use the vertex shader to efficiently update the UV coordinates, using a constant offset uniform parameter that you update each frame. That way you don't have to move UV data to the GPU every frame.

有关顶点位置,使用网格的基本浮动[] 并调用 setVertices()每帧更新它。信息这里

For the vertex positions, use your Mesh's underlying float[] and call setVertices() each frame to update it. Info here.

事实上,它可能会,如果你独自离开紫外线的与X位置,只是滚动Y位置起来更好看。保持填充的一对夫妇四边形关闭顶部和屏幕下方,只是移动顶级四底部它将滚动关闭屏幕后。

Actually, it might look better if you leave the UV's and the X positions alone, and just scroll the Y positions up. Keep a couple quads of padding off top and bottom of screen, and just move the top quad to the bottom after it scrolls off screen.

这篇关于绘制弧形自定义对象在LIBGDX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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