Carl Miller
Carl Miller

Reputation: 142

Do all Android games use a single canvas?

Should all View objects be redrawn every onDraw() procedure?

I'm coming from a Flash background so my initial thought was to draw static background images on one layer/canvas and then create another layer on top of that to handle more active animations, but this doesn't seem very practical to setup. Is my train of thought behind Android's View.onDraw() misguided here and is this something I shouldn't even be worrying about?

Edit: To elaborate a bit further on what I'm trying to figure out with the concept of onDraw() - Is there a way to use multiple canvases on a SurfaceView/View that will act as layers so I can manually draw on each individual canvas (to minimize what needs to be 'redrawn') without having to 'redraw' the graphics on other canvases, or is the SurfaceView/View's onDraw() absolutely necessary for updating any visual changes (in which case everything is 'redrawn' to the screen)?

Upvotes: 1

Views: 892

Answers (2)

edthethird
edthethird

Reputation: 6263

well, maybe not all but a Canvas can be considered a Scene. I use a Toon class, containing an X,Y coordinate, a Rect hitbox, and a Drawable. This class Toon also has a method:

public draw(Canvas c) {
    mDrawable.setBounds(mHitBox);
    mDrawable.draw(c);
}

Then, in the onDraw(Canvas c) method in the game loop, I just loop through all my Toon objects, and call the draw(c) method on them. Try not to manipulate objects in onDraw, they should ideally only be drawn.

Upvotes: 0

paulsm4
paulsm4

Reputation: 121809

Q: Should all View objects be redrawn every onDraw() procedure?

A: No - not necessarily

ALSO: definitely take a look at SurfaceViews:

http://developer.android.com/reference/android/view/SurfaceView.html

Upvotes: 1

Related Questions