I currently have a game written using the Android canvas. It is completely 2D, and I draw bitmaps as sprites on the canvas, and it technically works, but I have a few features that I need to add that will require drawing many more bitmaps on the screen, and there will be a lot more movement.
The app needs more power.
What is the best way to go from this method of drawing Bitmaps on a canvas to using OpenGL so I can draw them faster?
Canvas is the place or medium where perfroms/executes the operation of drawing, and Bitmap is responsible for storing the pixel of the picture you draw.
The Canvas class holds the "draw" calls. To draw something, you need 4 basic components: A Bitmap to hold the pixels, a Canvas to host the draw calls (writing into the bitmap), a drawing primitive (e.g. Rect, Path, text, Bitmap), and a paint (to describe the colors and styles for the drawing).
To create a Bitmap from a resource, use the BitmapFactory method decodeResource(): Bitmap = BitmapFactory. decodeResource(getResources(), R. drawable.
Matrix 🔢 A 3 by 3 Matrix that stores information which can be used to transform a canvas. A Matrix can store the following kind of transformation information: scale, skew, rotation, translation.
There are a couple platforms out there in the works for making 2d open gl games: http://www.rokonandroid.com/
http://www.andengine.org/
Unfortunately neither is as well developed as it's iPhone equivalents (cocos2d-iphone), but they will help you get off the ground faster than trying to interface with openGL right off the bat yourself.
I think you can get good performance out of a canvas.. but it takes a lot of work..
if you start off with a good performance graphics library, then even if you get a lot of things wrong, you probably will still end up with good performance :) lol
there is a competition running for the fastest drawing library... libgdx is currently winning...
https://github.com/libgdx/libgdx/wiki/A-simple-game
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With