I've been trying to use a class to create images of obstacles and nothing happens when I run it.

Mateusz Tomaszek 1 Reputation point

I'm trying to create a simple game and I wanted to use classes to have multiple obstacles to spawn and move from right to left. For now I was only focused on actually creating the obstcales anywhere on the screen but nothing seems to be working.

public class Obstacles
            public Point postion;
            public Size size;
            public System.Drawing.Bitmap image;

            public PictureBox createObstacle()
                PictureBox rock = new PictureBox();
                rock.Location = postion;
                rock.Size = size;
                rock.Image = image;
                rock.SizeMode = PictureBoxSizeMode.StretchImage;
                return rock;

Obstacles obstacles = new Obstacles();

obstacles.postion = new Point(500, 200);
obstacles.size = new Size(50, 50);
obstacles.image = Properties.Resources.pixil_frame_0;

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,373 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 82,036 Reputation points

    If you create Picture Boxes, you must add them to the Form, like :

    PictureBox p1 = obstacles.createObstacle();
    1 person found this answer helpful.
    0 comments No comments