Noob for game development, and I am unable to place AnimationDrawable on SurfaceView canvas. This is part of a simple game, the user touches the screen and the animated gif is placed in a place that looks like an explosion. I can accomplish this using Bitmap using the code below, but converting this to AnimationDrawable is where I got stuck. I could create an AnimationDrawable from an ImageView, but I can't find a way to get an ImageView on canvas either ...
Am I really wrong about that? Is there an easier way to get an animated gif to display in x, y coordinate on SurfaceView canvas?
Bitmap explodeBmp = BitmapFactory.decodeResource(getResources(), R.drawable.explode4); canvas.drawBitmap(explodeBmp, coords.getX()-(explodeBmp.getWidth()/2), coords.getY()-(explodeBmp.getHeight()/2), paint);
This throws a ClassCastException if I try to convert Bitmap to AnimationDrawable and fire it:
AnimationDrawable explosionAnimation = (AnimationDrawable) ((Drawable) new BitmapDrawable(explodeBmp)); explosionAnimation.start();
source share