If you want to work with the 2d draw api (e.g. not the GL one), a
typical way to organize your code is to have a view that knows how to
draw your static background and all the "pieces" (aka sprites) that
you need on top. However before drawing anything get the clip bounds
and check your sprites against the current clipping region. Then in
your game thread, simply post invalidate rectangles to your view to
redraw only the parts of the screen that changed.

E.g:

in your custom view:
public void draw(Canvas canvas, ...) {
   Rect clipRect = ...; // should be a member, not reallocated at each draw
   boolean useClipRect = canvas.getClipBounds(clipRect);
   // draw background
   ...
   // draw a sprite only if needed
  Rect r = my_sprite.getRect();
  if (!useClipRect || Rect.intersects(clipRect, r)) { draw sprite }
}

and then use View.invalidate (int l, int t, int r, int b) or
View.postInvalidate (int l, int t, int r, int b) to refresh your view.


Note if you have the Dev Tools in the emulator, in the development
section there's a flag to show screen invalidates, it marks all screen
refreshes as purple.

R/


On Sat, Mar 28, 2009 at 3:05 PM, robotissues <jason.van.an...@gmail.com> wrote:
>
> I am unsure of the jargon so please bear with me, I am seeking advice
> on the best way to go about drawing the graphics for an app I am
> developing.
>
> Imagine you are creating a game of checkers, where you can drag/drop
> one piece at a time to a blank space on the board.   When the piece is
> being moved, it seems to me that you should not need to redraw all of
> the pieces that are not being moved.
>
> Using the LunarLander example, is there a way to store the background
> image and only draw the piece being moved over it?  I have been trying
> to figure out a way to capture the canvas as an bitmap that is
> occasionally refreshed.  Is there a way to do this?
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to