isometric gui game

Started by
6 comments, last by pbivens67 6 months, 3 weeks ago

I am using c# and windows forms to make an isometric game, my question how do I move an image without the screen flickering. here is my code so far.

namespace WindowsFormsApp15
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        int x = 240, y = 220;

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Image myImage = Image.FromFile("iso3.png");
            for(int j=0; j<420; j+=20)
            {
                for(int i=0; i<520; i+=40)
                {
                e.Graphics.DrawImage(myImage, i, j);
                }
            }
            Image myImage_two = Image.FromFile("castle3.png");
            e.Graphics.DrawImage(myImage_two, 240, 160);
            Image myImage_three = Image.FromFile("player2.png");
            e.Graphics.DrawImage(myImage_three, x, y);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            y -= 5;
            Invalidate();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            y += 5;
            Invalidate();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            x -= 5;
            Invalidate();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            x += 5;
            Invalidate();
        }
    }
}
Advertisement
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

wow that worked thx

is there any way to animate an image using c# and windows forms?

@pbivens67 Does google not work on your computer? Animation on Windows Forms

You've picked a rather outdated and limited platform to develop games, you could at least go for WPF.

what tool should I use to animate a gif?

here is some code I have been working to animate a bmp, it does not draw anything to the screen, I don't know what to do next? I just need a little help.

        Bitmap[] Banner = new Bitmap[10];

        public Form1()
        {
            InitializeComponent();
            for (int i = 1; i < 2; i++) 
            {
                Banner[i] = new Bitmap("warrior.bmp");
            }
        }

        int k = 1;
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (k == 2)
            {
                timer1.Enabled = false;
            }
            k++;
        }

        void panelAnimation_Paint(object sender, PaintEventArgs e)
        {
            var image = Banner[k];
            e.Graphics.DrawImage(image, 100, 120, image.Width, image.Height);
            Invalidate();
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
        }

        private void button11_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
        }

This topic is closed to new replies.

Advertisement