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 6834821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:09:31+00:00 2026-05-26T23:09:31+00:00

I have a sprite class which has a draw method which draws an explosion.

  • 0

I have a sprite class which has a draw method which draws an explosion.
The class has an image property which is used as the image that will be drawn.

I wish to have it so that the image that is draw is changed every 5 seconds or so.

My question is: Using a timer control, how can I code it so the Image property is changed to a different image each tick?

For example, Image 1 ‘5 seconds’ > Image 2 ‘5 seconds’ > Image 3 ‘5 seconds’ > remove image.

Here is the draw method:

    public void DrawExplosion(Graphics graphics)
    {
        graphics.DrawImage(explosion_, xPos_, yPos_);
    }

and the Image property of the class

    public Image Explosion
    {
        get {return explosion_;}
        set {explosion_ = value;}
    }

Thanks for any help/guidance.

  • 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-26T23:09:31+00:00Added an answer on May 26, 2026 at 11:09 pm

    i noticed my answer was far to complex for the simple question asked. While I don’t believe it is incorrect I do think it complicates the matter. I wanted to leave it there in case someone else finds it useful. But here is a simplified attempt. It uses a timer external to the Sprite class, a button and a panel. I hope this is helpful.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace CustomControl
    {
    public partial class Form1 : Form
    {
        Sprites Explosion = new Sprites();
    
    
        public Form1()
        {
            InitializeComponent();
            //insert your images in this next line
            Explosion.Images=new Image[]{Properties.Resources.explode1,Properties.Resources.explode2,Properties.Resources.explode3};
            Explosion.ImageIndex = 0;
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            //Draw the first image right away
            Explosion.Draw(panel1.CreateGraphics(), 0, 0);
            //set the index to the next image
            Explosion.ImageIndex++;
        }
    
    
        private void timer1_Tick(object sender, EventArgs e)
        {
            //if the Imageindex is not greater then the number of images
            if (Explosion.ImageIndex < Explosion.Images.Count() )
            {
                Explosion.Draw(panel1.CreateGraphics(), 0, 0);
                Explosion.ImageIndex++;
            }
            //if it is greater then reset the imageIndex and turn off the timer
            else
            {
                Explosion.ImageIndex = 0;
                timer1.Enabled = false;
                //Clear your images, however you need to do that
                panel1.CreateGraphics().Clear(Color.White);
            }
    
    
        }
    }
    
    
    public class Sprites
    {
        public Image DisplayedImage { get { return Images[ImageIndex]; } }
        public int ImageIndex;
        public Image[] Images;
    
        public void Draw(Graphics graphics, int x, int y)
        {
            graphics.DrawImage(DisplayedImage, x, y);
        }
    
    
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the setup: I have a class called Sprite that contains an image
I have a class which extends UIComponent and draws directly onto a Sprite contained
I have a class called Sprite, and ballSprite is an instance of that class.
I have a sprite loaded from a PNG that has an alpha channel. The
If I have a sprite, with which I have drawn some stuff, how do
I have a class which extends the Sprite object in as3. I need to
i have a class method in which i am creating and returning the class
I have a class which makes a url request and stores data from that
I have a base class called SpriteSheet which has two children, RotatedSpriteSheet and FlippedSpriteSheet.
I have 2 sprites which when drawn together make up the correct image on

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.