there is no Sprite class available like the one in J2ME. like nicholas
suggests - u might want to write your own custom sprite class with the
same functionality. i managed to avoid it on my current project, but i
guess sooner or later i'll have to write my own game API. here is what
i have in mind:

1) the basic Sprite class will extend the BitmapDrawable class in the
android.graphics.drawables package
2) the new extended class will have a Rect or a RectF member variable
to keep track of its position on screen. The Rect and RectF classes
already have useful methods that can be used for detecting collisions
3) the BitmapDrawable class has an existing setBounds() method which
contains the actual position to draw the screen

   the methods for translating / scaling a bitmap within its bounds
are not very useful especially when you have a number of "frames" in
your sprite. perhaps u'll need to have an array of bitmaps where each
bitmap represents one frame in the animation. again - this will be
specific to the game at hand.

  actually, ALL of the above tasks, including the animation
functionality can be implemented using the AnimationDrawable class
that is part of the same graphics package as BitmapDrawable. however,
despite many attempts i was unable to get it to work in my program.
the animation never moved beyond the first frame. apparently other
people have faced the same problem ... but i am yet to receive a
response to my query posted a few weeks ago. after extensive googling
on the subject i came across some complicated solutions, but i never
got round to implementing them coz i really didnt need animation in my
current project. i managed to create a workaround using static images
instead.
   i'd suggest u try AnimationDrawable once ... if it works then it
will solve all your problems.

~ayush.



On May 17, 8:31 pm, Nicholas Radford <nikradf...@googlemail.com>
wrote:
> Take a look at 
> <http://developer.android.com/reference/android/graphics/Canvas.html#d...,
> android.graphics.Rect, android.graphics.RectF, 
> android.graphics.Paint)>http://developer.android.com/reference/android/graphics/Canvas.html
>
> drawBitmap calls, (if your using the Android graphics and not the OpenGl
> graphics libs)
>
> You'll see this one in particular
>
> drawBitmap<http://developer.android.com/reference/android/graphics/Canvas.html#d...,
> android.graphics.Rect, android.graphics.RectF, android.graphics.Paint)>(
> Bitmap <http://developer.android.com/reference/android/graphics/Bitmap.html>
>  bitmap, 
> Rect<http://developer.android.com/reference/android/graphics/Rect.html>
>  src, 
> RectF<http://developer.android.com/reference/android/graphics/RectF.html>
>  dst, 
> Paint<http://developer.android.com/reference/android/graphics/Paint.html>
>  paint)Draw the specified bitmap, scaling/translating automatically to fill
> the destination rectangle.
>
> Where Bitmap is your Sprite sheet, src is a rectangle on your sprite sheet
> (just the section you want to draw) and dst is a destination rectangle on
> the canvas (where you want to draw it), and paint is your paint object.
>
> I'd give example code, but I've not actually written anything for android
> yet, so my example code would not be the best to learn from. Hopefully
> though, that function will show you the way.
>
> Nik
>
> 2009/5/17 G. Murat Taşbaşı <gmt...@gmail.com>
>
> >         Hi guys,
>
> >         For a 2D game programming, I'm trying to learn about loading an
> > image file for all states of a game character (simply a walking soldier lets
> > say) and simply animate it. I think this classic method is called as sprite
> > imaging that you load whole image of all states of the character that you
> > want to animate.
>
> > Is there anyone that can provide some sample code about this or at least
> > can you tell me which classes to use, how to refer some 'part of' whole
> > image file and animate it etc.
>
> >         Your help is much appreciated.
>
> >         Thanks a lot.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to