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

The Archive Base Latest Questions

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

I’m just starting C#, and creating my first game, but just ran into a

  • 0

I’m just starting C#, and creating my first game, but just ran into a problem.
I have a picturebox array

PictureBox[] obstacles = new PictureBox[20];

And I’m trying to declare 20 new random location pictureboxes inside it.

    private void Game_Load(object sender, EventArgs e)
    {
        player.Size = new Size(20, 20);
        player.Location = new Point(20, 240);
        player.Image = Properties.Resources.playerImg;
        Controls.Add(player);

        for (int i = 0; i < 20; i++)
        {
            obstacles[i] = new PictureBox();
            obstacles[i].Size = new Size(10, 10);
            obstacles[i].Location = new Point(50, 340);
            obstacles[i].BackColor = Color.Red;
            Controls.Add(obstacles[i]);
        }
    }

I know it’s not spawning them into a random location yet, but I won’t do that ’till I get them to spawn at all.
Now when I try to create a method to use picturebox array, it’s objects (picturebox[0-19]) are all just null?

private void JustAnOtherTest(PictureBox obj)
{
    for (int y = obj.Top; y < obj.Top + obj.Height - 1; y++)
    {
        MessageBox.Show("Testing out!", "Test");
    }
}

Now calling: JustAnOtherTest(obstacles[1]); and adding a watch for obj in JustAnOtherTest method will just give me a null, why is that?

EDIT: Seems like it never goes into the for loop, cause it exits Game_Load once it gets to player.Image = Properties.Resources.playerImg; which probably means that the problem is in the resource files… :S

EDIT2: Yeah, I was right, the problem was within resource files. I had messed up with some namespaces and it couldn’t find the resource file cause it was in a different namespace, but I ain’t so sure why it didn’t give an error on that. How ever, after fixing all the namespaces, works just fine. 🙂

  • 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-26T08:31:56+00:00Added an answer on May 26, 2026 at 8:31 am

    There are three possibilities

    1) Game_Load() is not being called before you access the array. Stick a break point in it and see if it fires.

    2) You are somehow creating two variables called obstacles. Where is it defined exactly?

    3) Something is clearing it again before you access it.

    The most basic check is to put a breakpoint in your create loop, and check that the new is working ok at that point.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't

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.