C#
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.
11,296 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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;
obstacles.createObstacle();
If you create Picture Boxes, you must add them to the Form, like :
PictureBox p1 = obstacles.createObstacle();
this.Controls.Add(p1);