I'm trying to implement drawing a line with a finger, similar to a Pencil tool in image editors. From what I've found on AndEngine, it seems like the recommended approach would be to create a line entity on every finger move, from the previous position to the new one. To me it seems rather inefficient to mimic this raster tool by vector graphics: apart from creating tens on objects per simple swipe, I guess that all these objects are repainted on each frame which is bad for speed. So I'm looking for a way to do all the painting on a bitmap canvas and draw it as a single entity. Am I missing something conceptually or did I just overlook some method?
1 Answer
Yes, you are missing something conceptually - AndEngine is based on OpenGL ES. Now OpenGL is very well suited to the following use case:
- Load a texture to bitmap memory
- Define texture region in the texture
- Create transformation (scale, position, ...)
- Draw the Region from the texture memory to display
AndEngine exploits this by defining a 2D sprite that is a representation of the region. It uses ortographic projection to show textured quads. It is certainly not suited for drawing on "canvas".
Using Line object is not recommended, because it is up to the OpenGL ES implementer how the line will look like in the end. Each implementation has to follow certain rules, but still the lines can look different.
So your best bet is to:
- Use the line and bear the consequences (I do that in my game btw)
- Use line texture + sprite
- Temporarily show something (draft using 1 or 2), then create a bitmap from it and load it to texture memory as a new texture and then show it.
-
\$\begingroup\$ Thank you, I've already come to the conclusion that OpenGL doesn't allow what I want, but confirmation from an experienced person is always good :) I chose to switch from OpenGL to CPU graphics. My game is pretty simple, so it should suffice. Currently I'm trying candroidengine. \$\endgroup\$– lapisOct 15, 2013 at 13:34