0

The "shooter" subclass

class Shooter : Box
{
    public bool goleft;
    public bool goright;



    public Shooter(float startx, float starty)
    {
        pic = resizeImage (Properties.Resources.shooter, new Size(50,50)); // resize image
        goleft = false;
        goright = false;
        x = startx;
        y = starty;

    }

And this is the main class from which it inherited the code.

class Box
{
    public Image pic;
    public float x;
    public float y;
    public int speed;

    public Box()
    {
        x = 0;
        y = 0;
        speed = 0;
    }
    // Image Resizing Code
    public static Image resizeImage(Image imgToResize, Size size)
    {
        return (Image)(new Bitmap(imgToResize, size));
    }
    // image resizing code


    public void Draw(Graphics g)
    {
        g.DrawImage(pic, x, y);
    }
    // some code bellow that basically states the borders and hit boxes.
}

So, yeah, I'm just trying to figure out how to animate a gif which is essentially built by a constructor... The shooter shows up, I can move it around but the problem is, is that it's just not spinnin'. Hope you guys can figure it out. Thanks :D

ferc
  • 560
  • 6
  • 21
  • 3
    What are you targetting: Winforms, WPF, ASP..? Always __TAG__ your question correctly! – TaW Apr 28 '18 at 20:27
  • It's tagged as c#... –  Apr 28 '18 at 20:29
  • c# is the language, what's the UI framework you are using is what Taw asked – Camilo Terevinto Apr 28 '18 at 20:34
  • oh, it's visual studio. –  Apr 28 '18 at 20:36
  • Visual Studio is the IDE, which of course you are using it. It seems you are not very clear on the technologies you are using – Camilo Terevinto Apr 28 '18 at 20:39
  • @AlcoGoblin "Visual Studio" is not a UI framework, it's an IDE. What project-template did you select for your project? – Dai Apr 28 '18 at 20:39
  • It's Windows Forms App (.Net Framework). I don't know what else to tell you. –  Apr 28 '18 at 20:40
  • I could guess that is is WinForms. The point is that you always should __Tag__ the target so people who scan the [questions page](https://stackoverflow.com/questions/tagged/c%23?sort=newest&pageSize=30) can see whether it is in their field of expertise. I for example do'nt do ASP or WPF so I can skip those questions.. – TaW Apr 28 '18 at 21:03
  • @TaW so the only way for me to do it is to kind of redo the code and put it as a picture box? –  Apr 28 '18 at 21:10
  • To make a gif animation run it neesd to be in a PictureBox.Image. Drawing it will only paint the pixels of the 1st frame. – TaW Apr 28 '18 at 21:10
  • Well either that or, if is simly spinning you might consider drawing it rotated in code. [See here](https://stackoverflow.com/questions/26525965/rotate-a-graphics-bitmap-at-its-center/26527737?s=3|37.5728#26527737) for an example – TaW Apr 28 '18 at 21:13
  • 2
    @TaW I think it would be simpler for him to derive its `Box` class from `Panel` and use [`ImageAnimator`](https://msdn.microsoft.com/en-us/library/system.drawing.imageanimator(v=vs.110).aspx) to rotate the bitmap frames. It takes care of all the timings.. – Jimi Apr 28 '18 at 21:25
  • Maybe yes, maybe no. For a simple spin it may be fine to draw rotated images, for anything more complicated probably not. __Interesting link__! Thanks! - @ferc may want to include it in the answer.. – TaW Apr 28 '18 at 21:39

1 Answers1

1

Your GIF is not being animated because your Box class simply doesn't support it.

If you want to animate the image, you can't open it as a Bitmap, you need to get the image data and do the animation manually, or use a PictureBox to display the image. Here's an example of how to do it manually. Note that in order to resize the GIF, you also need to do it frame by frame.

ferc
  • 560
  • 6
  • 21