将 SVG 文件与 libgdx 一起使用 [英] Using SVG files with libgdx

查看:24
本文介绍了将 SVG 文件与 libgdx 一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正计划创建平板电脑应用.我想请教一些指导.

我有 SVG 格式的图片,例如 这张.p>

使用 SVG 很容易,您只需将填充参数更改为不同的颜色,但据我所知,没有简单/稳定的 svg 处理可用于 libgdx.我仍然想使用 svg 文件为我的应用创建/存储图像.

  • 您会推荐哪种处理路径?
  • 有没有一种简单的方法可以为 com.badlogic.gdx.math.bezier 或多边形对象转换 svg 路径/形状,然后在屏幕上绘制它们/在这些形状内获取用户输入(点击)?
  • 或者我应该使用不同的对象/路径吗?

形状可以组合在一起,例如我想让房子里的两个窗户同时改变颜色.

解决方案

LibGDX 的编写方式是它为您提供了一种较低级别的方式来进行这种类型的渲染,但不提供开箱即用的方式来渲染 SVG.这实际上取决于您是在寻找具有性能的东西还是只是希望它绘制基本形状.

要简单地渲染形状,您可以使用 ShapeRenderer.这为您提供了一个非常接近 Java2D 绘图方式的接口.也许为了快速绘制一些基本的东西,这可能会很方便.

如果您想做一些更强大的渲染版本,您可能需要考虑使用 Mesh 并使用 OpenGL ES 的着色器.您可以在 LibGDX 测试 以及在线搜索示例/教程.

如果您想将 SVG 转换为纹理,您需要查看 Pixmap 然后你可以用它创建一个纹理并用 Spritebatch 渲染.您将需要使用 Pixmap 编写要着色的像素等.但是,这样做会生成一个非托管纹理(即,当用户在按下返回或使设备进入睡眠状态后返回应用程序时,您必须重建它).

I'm planing to create tablet app. I would ask for some guidance.

I have pictures in SVG format like this one.

With SVG it is easy, You just change fill parameter to different color but as I understand, there is no easy/stable svg processing to use with libgdx. I still want to use svg files to create/store images for my app.

  • What processing path would You recommend?
  • Is there an easy way to convert svg paths/shapes for com.badlogic.gdx.math.bezier or polygon objects and then draw them on screen/get user input (tap) inside this shapes?
  • Or should I use different objects/path?

Shapes could be grouped together for example I want two windows in a house to change color at once.

解决方案

The way LibGDX is written is it gives you a lower level way to do this type of rendering, but doesn't offer out of box ways to render SVG. It really depends on if you are looking for something with performance or just simply want it to draw basic shapes.

To simply render shapes you could use something like ShapeRenderer. Which gives you a very close interface to the Java2D way to draw things. Maybe to quickly draw some basic stuff this might be handy.

If you are wanting to do some more robust version of rendering you will probably want to look into using a Mesh and working with shaders for OpenGL ES. You can find examples of these in the LibGDX tests as well as searching online for examples/tutorials.

If you want to turn the SVG into a texture you will want to look at Pixmap and then you can create a Texture with it and render with a Spritebatch. You will need to write the pixels you want to color and such with the Pixmap. However, doing it this way will generate an unmanaged texture (i.e. you will have to rebuild it when a user comes back to the app after pressing back or putting the device to sleep).

这篇关于将 SVG 文件与 libgdx 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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