Hi,
I am attempting to teach myself C# Game Basics from book (Learning C# by Programming Games)
In Chapter 5 we are introduced to a simple Game where the cursor is replaced by a picture of a balloon. This is about where Objects, Classes, Methods and Properties are explained. I am now looking at the code for this game and I am confused about a few things I was hoping someone could help me understand. So here is the code: (my question is inside // // )
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
class Balloon : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D balloon, background;
Vector2 balloonPosition;
static void Main()
{
Balloon game = new Balloon();
game.Run();
}
public Balloon()
{
Content.RootDirectory = "Content";
graphics = new GraphicsDeviceManager(this);
}
//
1. Content is a property of Game which is essentially a location on the pc ? Then RootDirectory is a Method that specifies where all the assets are located? so Content.RootDirectory gives the property content a location.
Why can't you just write Content = "Content"
2. GraphicsDeviceManager is a class with a parameter the object we created called game ? we have created a new object in this line: graphics ?
3. what is difference between a parameter and a property of an object ?
//
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
balloon = Content.Load<Texture2D>("spr_lives");
background = Content.Load<Texture2D>("spr_background");
}
protected override void Update(GameTime gameTime)
{
MouseState currentMouseState = Mouse.GetState();
balloonPosition = new Vector2(currentMouseState.X, currentMouseState.Y);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.White);
spriteBatch.Begin();
spriteBatch.Draw(background, Vector2.Zero, Color.White);
spriteBatch.Draw(balloon, balloonPosition, Color.White);
spriteBatch.End();
}
}