Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing bitmaps faster on Android canvas or OpenGL

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?

like image 979
Ben Mc Avatar asked Jun 15 '10 18:06

Ben Mc


People also ask

What is bitmap and canvas in android?

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.

What is canvas drawing in Android?

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

How do I create a bitmap in canvas?

To create a Bitmap from a resource, use the BitmapFactory method decodeResource(): Bitmap = BitmapFactory. decodeResource(getResources(), R. drawable.

What is matrix in canvas android?

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.


2 Answers

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.

like image 172
peter Avatar answered Oct 18 '22 13:10

peter


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

like image 29
hamish Avatar answered Oct 18 '22 14:10

hamish