Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SVG files with libgdx

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.

like image 940
tester.one Avatar asked Mar 05 '13 10:03

tester.one


1 Answers

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).

like image 64
Jyro117 Avatar answered Sep 18 '22 14:09

Jyro117