Hi,


I am fairly new as an android programmer (although I have many years
experience in C++).  I have a question regarding the smooth animation
of objects when drawing on a canvas using SurfaceView using a separate
rendering thread.

For the sake of discussion, let's say I have a ShapeDrawable 'sd' that
I want to move smoothly across the screen.  My first attempt at this
was to decide its position using the sd.setBounds(int, int, int, int)
and then call sd.draw(Canvas).  This works fine, and I get an
excellent framerate (~60FPS), but movement is still a bit jerky due to
the fact that setBounds() does not take floating point values
(resulting in the smallest possible move being at least one whole
pixel.

My next attempt was to shift the canvas itself rather than calling
sd.SetBounds(), using a transformation matrix.  This can be done with
floating point values, and the animation becomes visibly smoother, but
now I have another problem: garbage collection.

It seems as if, when I use a matrix to shift the canvas, there is some
memory allocation going on behind the scenes.  It does not seem to
matter whether I use the matrix that comes with the canvas or if I
supply my own preallocated one - as soon as I am changing the matrix
content, logcat shows me that the garbage collector becomes active
every 250 frame or so.  This does not happen when I use the
setBounds() approach - only when I use the matrix approach.

Each time the garbage collector kicks in, there's an annoying drop in
framerate.  I have not figured out a way to avoid this.

My question is therefore threefold:
1) Is there a way to place a ShapeDrawable (or any other Drawable) on
the canvas, using sub-pixel precision?
2) Is there a way to handle matrix transformations where you have
control of the allocation/deallocation of memory? (so that you can
prevent the garbage collector from regularly kicking in).
3) If the answer is 'no' to both above, is there another/better way to
obtain smooth sprite animation?

Thanks,
Odd

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

Reply via email to