Droid
Droid

Reputation: 569

Android game canvas

I'm making an element of the game, where a man shoots a rocket to the target, then the target explodes. I'm doing this with canvas and threads, always redrawing the whole screen. Can it be done other way? Because if there will be a lot of action, game will eat a lot of memory. So I'm looking for optimization and how to animate objects without redrawing the whole screen.

Upvotes: 1

Views: 376

Answers (2)

Whitney
Whitney

Reputation: 1237

If you are using surfaceview or textureview, you can lock part of the screen and just redraw that. (I recommend textureview over surfaceview).

Canvas android.view.TextureView.lockCanvas(Rect dirty). public Canvas lockCanvas (Rect dirty). Added in API level 14. Just like lockCanvas() but allows specification of a dirty rectangle. Every pixel within that rectangle must be written; however pixels outside the dirty rectangle will be preserved by the next call to lockCanvas(). This method can return null if the underlying surface texture is not available (see isAvailable() or if the surface texture is already connected to an image producer (for instance: the camera, OpenGL, a media player, etc.)

Upvotes: 1

Klitos G.
Klitos G.

Reputation: 836

Just a suggestion.

why don't you use a gaming framework such as libgdx? It takes you off from pure android code but it will let you focus on your game rather than memory management.(and your game will be playable on other platforms also)

In case you like the idea, there are also other tools (unity, gamesalad, etc)

Upvotes: 1

Related Questions