Jump to content
  • Advertisement
phil67rpg

c# game

Recommended Posts

The problem is your BMP cannot be found. Put it in the Release or Debug folder (depending on which you're running) and it will work.

I just tried it and it works fine.

TestGraphics.zip

Edited by duke_meister

Share this post


Link to post
Share on other sites
Advertisement
1 minute ago, phil67rpg said:

how do I get the app to find the bmp, yes it does  exist on the desktop.

see the project I attached in the previous message.

It can't magically find the image on your desktop :) How does it know it's there? Either provide the full path to it, or move it as I suggested.

Edited by duke_meister

Share this post


Link to post
Share on other sites

I moved as suggested and yes it works, thanks for all the help, I was looking in the wrong folder.

Share this post


Link to post
Share on other sites
Just now, phil67rpg said:

I moved as suggested and yes it works, thanks for all the help, I was looking in the wrong folder.

No problem :) Keep at it. I did quite a bit of graphics on WinForms not so long ago (although it's outdated, it's still very useful for learning and rapid development). I'm prototyping a game in it right now.

Share this post


Link to post
Share on other sites
9 minutes ago, phil67rpg said:

I am still working on my blackjack game but I am using graphics. thanks for all the  help.

No problem. BTW you should dispose() the BMP you created. Rule of thumb is to dispose resources you create (at the right time) and not those you don't create.

Share this post


Link to post
Share on other sites

here is my updated code, is there anyway I can streamline my code so far.

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Bitmap bitmap_two = new Bitmap("c02.bmp", true);
            Bitmap bitmap_ace = new Bitmap("c01.bmp", true);
            g.DrawImage(bitmap_two, 20, 20);
            g.DrawImage(bitmap_ace, 40, 40);
            g.Dispose();
        }

 

Share this post


Link to post
Share on other sites
20 minutes ago, phil67rpg said:

here is my updated code, is there anyway I can streamline my code so far.


        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Bitmap bitmap_two = new Bitmap("c02.bmp", true);
            Bitmap bitmap_ace = new Bitmap("c01.bmp", true);
            g.DrawImage(bitmap_two, 20, 20);
            g.DrawImage(bitmap_ace, 40, 40);
            g.Dispose();
        }

 

Yes but beware premature optimization :)

Don't dispose the graphics object. You didn't create it, you're only aliasing it by assigning to another variable.

About the only thing I'd add at this point, is to surround the bitmap creation/usage in a using() statement (but not the Graphics g = part).

edit: ok another general thing, don't use hard-coded strings like "c02.bmp". I know it's only early but I think this is worth mentioning early so that you apply that to all your code as you write it. Either create a constant for it, or better, store and look it up somehow. I'll leave that to you.

Edited by duke_meister

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!