Hello Community,
having visited Google I/O in May one thing I had put to my ToDo list was adding a feature to AndEngine that allows you to easily render SVGs (Scalable Vector Graphics) onto a Texture(Region). Romain Guy dropped a hint on the svg-android project on GoogleCode, which I started looking over about 2 weeks ago.
I was amazed by the simplicity of how many features of SVG can be easily mapped to the Canvas API in Android. I had started off with their original code but soon noticed that they primarily supported a kind of limited SVG format called SVG Basic 1.1 that is not supported as an export format of Inkscape, while it could not parse InkScapes SVG output
.
Besides that limitation, a couple of bugs, some missing object orientation and literally hundreds of SVG special cases, I basically came up with a complete recode, that supports the following features: (fixes and feature-wise differences from the original are colored red)
Features
- Groups
- Inheritance of group-transformations and attributes/properties
- Colors
- Opacity
- Formats:
- rgb(rrr,ggg,bbb)
- #RRGGBB
- #RGB
- Gradients
- Inheritance (lazy initialization, including transform/stop-inheritance)
- Types:
- LinearGradients
- RadialGradients
- Rectangles
- Circles
- Ellipses
- Polygons
- Polylines
- Paths
- SubPaths
- Fillrule
- even-odd
- Commands:
- M/m – Move to
- Z/z – Close path
- L/l – Line to
- H/h – Horizontal ine to
- V/v – Vertical line to
- C/c – Cubic bezier to
- S/s – Smooth cubic bezier to
- Q/q – Quadratic bezier to
- T/t – Smooth quadratic bezier to
- A/a – Arc to
Supported formats
- Optimized Inkscape-SVG (Recommended Format)
- Inkscape SVG
- Adobe Illustrator SVG
And this is what you can do with it:
Quite nice, hm?
The code to make use of this is (as always) absolutely trivial:
final int size = (isHighResDevice()) ? 128 : 64;
ITextureRegion textureRegion = SVGTextureRegionFactory.createFromAsset(this.mBuildableTexture, this, “gfx/vector.svg”, size, size);
A full example is available here: http://code.google.com/p/andengineexamples/source/browse/src/org/anddev/andengine/examples/SVGTextureRegionExample.java
The SourceCode of the project is available here: http://code.google.com/p/andenginesvgtextureregionextension/
A precompiled, ready-to-use jar is available here: http://andengineexamples.googlecode.com/hg/lib/andenginesvgtextureregionextension.jar
Best Regards,
Nicolas






June 14th, 2011 20:46
Wait… is this a step towards replacing flash?…
June 14th, 2011 21:19
AndEngine runs solely on Android, there is no need to replace Flash there.
June 23rd, 2011 00:56
E P I C.
September 11th, 2011 22:07
Hello Nicolas
“A precompiled, ready-to-use jar is available here: http://andengineexamples.googlecode.com/hg/lib/andenginesvgtextureregionextension.jar”
link is 404!
Greetings
Tamas
helloandroid.com
October 21st, 2011 09:30
AndEngine is now a library project.
September 20th, 2011 11:12
Seems pretty
it is excellent , i must test this
cool to make game with Comics look
Thanks a lot