Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6249743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:17:43+00:00 2026-05-24T13:17:43+00:00

Noob to game development and I’m having trouble placing an AnimationDrawable onto a SurfaceView

  • 0

Noob to game development and I’m having trouble placing an AnimationDrawable onto a SurfaceView canvas. It’s part of a simple game, user touches screen and an animated gif is placed at that location that looks like an explosion. I can accomplish this with a Bitmap using the code shown below, but converting this to an AnimationDrawable is where I’m stuck. I could create the AnimationDrawable from an ImageView, but I can’t find a way to get the ImageView onto the canvas either…

Am I going about this in the wrong way? Is there a simpler way to get an animated gif to display at an x,y coordinate on a SurfaceView’s 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 the Bitmap to an AnimationDrawable and start it:

AnimationDrawable explosionAnimation = (AnimationDrawable) ((Drawable) new BitmapDrawable(explodeBmp));
explosionAnimation.start();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:17:43+00:00Added an answer on May 24, 2026 at 1:17 pm

    After continuous digging I’ve found the answer… seems I like answering my own questions here.

    Just found the Movie class. I can load my animated gif into it using an InputStream, then play the movie bit by bit in my onDraw() because the Movie class supports a draw() method where I can supply my canvas and x,y coordinates.

    Here’s the code snippit below:

    InputStream is = context.getResources().openRawResource(R.drawable.dotz_explosion);
    Movie explodeGif = Movie.decodeStream(is);
    
    ...
    
    @Override
    protected void onDraw(Canvas canvas) {
        ...
          GraphicObject explosion = (GraphicObject)ex.next();
    
          long now = android.os.SystemClock.uptimeMillis();
          if (explosion.getMovieStart() == 0) { // first time
             explosion.setMovieStart(now);
          }
    
          int relTime = (int)((now - explosion.getMovieStart()) % explodeGif.duration());
          if ((now - explosion.getMovieStart()) >= explodeGif.duration()) {
             removeArrayExplosions.add(removeIndex);
             explosion.setMovieStart(0);
          } else {
             explodeGif.setTime(relTime);
             explodeGif.draw(canvas, explosion.getX()-(explodeGif.width()/2), explosion.getY()-(explodeGif.height()/2));
          }
        }
       ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created this game thing in order to learn OOP and I'm having trouble
I am a noob learning android and building a simple game at the same
Noob here - I'm working on a simple Javascript calculator, and I'm using lists
I'm currently working on learning some game development with Java. I'm working on the
noob question regarding ios development. In a previous project, I have a UITableViewController, to
I have been learning C++ by diving into a project, a simple 2d game.
I am creating a simple game in android so I can create something and
I'm a noob database / game dev (actually this will be my first game)
I'm a noob programmer who recently created a 2d puzzle game in Flash. To
I've been coding a simple android game with openGL ES 1.0 and require a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.