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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:22:24+00:00 2026-06-16T07:22:24+00:00

I’m writing a simple game – snake. I would like to have background and

  • 0

I’m writing a simple game – snake. I would like to have background and my snake on it. I think that the best way is use two pictureBox (one with background and second – transparent with snake on it).

This is a good way? And how can I put several small images (snake’s segments) on one picture box in different places (just copy pixel’s (one after one) from image to pictureBox or maybe there is fastest way – putting all image in correct place)? I have pictureBox with background (parent) and and another, transparent (child) on it now.

The result should be look something like that:

sample Image

I’ve made something like that (thanks to @dotTutorials), but my snake’s segments are a little bit bigger than original images and cookie is smaller. Where can be a problem?

Drawing Code:

public Bitmap PrinPlayground()
{

    char[,] tempPitch = play.getPitch();

    Graphics g = pb2.CreateGraphics();
    Bitmap bitmap = new Bitmap(512, 512);
    Graphics BBG = Graphics.FromImage(bitmap);

    Bitmap head = CookieSnake.Properties.Resources.head;
    Bitmap body01 = CookieSnake.Properties.Resources.body01;
    Bitmap tail = CookieSnake.Properties.Resources.tail;
    Bitmap cookie = CookieSnake.Properties.Resources.cookie;

    BBG.Clear(Color.Transparent);

    for (int i = 0; i < 16; i++)
        for (int j = 0; j < 16; j++)
        {
            if (tempPitch[i, j] == 'H')
            {
                BBG.DrawImage(head, new Point(32*j, 32*i));
            }
            else if (tempPitch[i, j] == 'B')
            {
                BBG.DrawImage(body01, new Point(32*j, 32*i));
            }
            else if (tempPitch[i, j] == 'T')
            {
                BBG.DrawImage(tail, new Point(32 * j, 32 * i));
            }
            else if (tempPitch[i, j] == 'C')
            {
                BBG.DrawImage(cookie, new Point(32 * j, 32 * i));
            }
        }
    g.DrawImage(bitmap, new Point(0,0));
    return bitmap;
}

Result:

enter image description here

  • 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-06-16T07:22:25+00:00Added an answer on June 16, 2026 at 7:22 am

    The best way to achieve this is definitely to use the ‘Graphics’ class. Please look further into the GDI, and the namespace System.Drawing.

    If you want to use a Picturebox representing the game space, you can easily implement graphics to a picturebox as well, by calling the member CreateGraphics.

    I hope this helps you! 🙂
    Please notice that when you get into serious game development, you’ll have to find a better alternative than GDI. I personally prefer the XNA library

    Example usage of GDI [This written fast, and should not be copy – pasted. However; It is a good point of origin :)]

        Graphics g = pictureBox1.CreateGraphics();
        Bitmap BB = new Bitmap(pictureBox1.Width, pictureBox1.Height);
        Graphics BBG = Graphics.FromImage(BB);
    
        Bitmap Background = (Bitmap)Bitmap.FromFile("BackgroundPicture.png");
        Bitmap Head = (Bitmap)Bitmap.FromFile("SnakeHead.png");
        Bitmap Tail = (Bitmap)Bitmap.FromFile("SnakeTail.png");
    
        Point snakeLocation = new Point((BB.Width / 2) - (Head.Width / 2), (BB.Height / 2) - (Head.Height / 2));
    
    
        while (true) {
            #region Update
            // update method here!
            snakeLocation.X += 1;
            #endregion
    
            #region Draw
            BBG.Clear(Color.CornflowerBlue);
            BBG.DrawImage(Background, new Point(0, 0));
    
            BBG.DrawImage(Head, snakeLocation);
            BBG.DrawImage(Tail, new Point(snakeLocation.X - Head.Width, snakeLocation.Y));
    
            g.DrawImage(BB, new Point(0, 0)); // draw to screen
            #endregion
        }
    

    UPDATE: The DrawImage method also accepts a RectangleF input. A RectangleF consits of 4 datatypes, float X, float Y, float Width and float Height.

    With a RectangleF you can easily specify the size of the drawn image. Take a look at the code below:

    public Bitmap PrinPlayground() {
    
                char[,] tempPitch = play.getPitch();
    
                Graphics g = pb2.CreateGraphics();
                Bitmap bitmap = new Bitmap(512, 512);
                Graphics BBG = Graphics.FromImage(bitmap);
    
                Bitmap head = CookieSnake.Properties.Resources.head;
                Bitmap body01 = CookieSnake.Properties.Resources.body01;
                Bitmap tail = CookieSnake.Properties.Resources.tail;
                Bitmap cookie = CookieSnake.Properties.Resources.cookie;
    
                BBG.Clear(Color.Transparent);
    
                for (int i = 0; i < 16; i++)
                    for (int j = 0; j < 16; j++) {
                        if (tempPitch[i, j] == 'H') {
                            BBG.DrawImage(head, new RectangleF(new Point(32 * j, 32 * i), new SizeF(/*Adjust the size after your pleasure*/32, 32)));
                        }
                        else if (tempPitch[i, j] == 'B') {
                            BBG.DrawImage(body01, new RectangleF(new Point(32 * j, 32 * i), new SizeF(32, 32)));
                        }
                        else if (tempPitch[i, j] == 'T') {
                            BBG.DrawImage(tail, new RectangleF(new Point(32 * j, 32 * i), new SizeF(32, 32)));
                        }
                        else if (tempPitch[i, j] == 'C') {
                            BBG.DrawImage(cookie, new RectangleF(new Point(32 * j, 32 * i), new SizeF(/*Half the size of the head [Adjust after your needs!]*/32 / 2, 32 / 2)));
                        }
                    }
                g.DrawImage(bitmap, new Point(0, 0));
                return bitmap;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I would like to count the length of a string with PHP. The string

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.