Tuesday, 19 January 2010

Configuration System Failed to Initialize

Short and sweet.

If you get a "Configuration System Failed to Initialize" message from Visual Studio when launching your project, chances are you've added a random character into your app.config or managed to corrupt the file in some other way so that it's no longer valid XML.

Labels:

Bookmark and Share

Thursday, 2 April 2009

Getting Started with XNA Game Development Studio 3.0

XNA Game Studio is now in it's third incarnation and well worth having a play with if you've even a passing interest in developing your own games. It includes Hardware acceleration and an API geared towards moving 2D and 3D graphics around the screen - and is so much easier to pick up than the old Managed DirectX.

You can download it here, and it can even be used in conjunction with the Microsoft C# Express edition.

I'm going to illustrate how easy it is to get started, by displaying a 2D Sprite, which will be hardware accelerated, and subsequently moving it around the screen.

Here's the sprite we'll be using:



I know, I'm so artistic.

Once you've got XNA installed, load up Visual Studio and create a new XNA Game Studio project, selecting the one labelled Windows Game (3.0).

Open up the solution explorer if it's not already visible, right click content, then Add Exisiting, and choose the location that you saved the above sprite to. You should then see Sprite1.png appear under Content in the solution explorer.

Now, open up Game1.cs and add the following two declarations inside the Game1 class:


Texture2D playerTexture;
Vector2 playerPosition;

These will hold the sprite texture, and position respectively. Now we need to load our sprite into memory. Find the LoadContent method, and add to it so it looks like the following:

protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);

// TODO: use this.Content to load your game content here
playerTexture = Content.Load<Texture2D>("Sprite1");
}

Likewise, do the same for the Initialise method, where we'll set the initial position of the player:

protected override void Initialize()
{
// TODO: Add your initialization logic here
playerPosition = new Vector2(20, 20);

base.Initialize();
}

Done that? Good. Finally, we need to draw the sprite on the screen. Find the Draw method, and add code so it looks as follows:

protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);

// TODO: Add your drawing code here
spriteBatch.Begin();
spriteBatch.Draw(playerTexture, playerPosition, Color.White);
spriteBatch.End();

base.Draw(gameTime);
}

Now press F5, and all being well you'll see your sprite on the screen:



Now let's add the ability to move our sprite up and down. Find the Update method and add the following code to allow our player to be moved up and down with the arrow keys:

protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();

// TODO: Add your update logic here

if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Down))
{
float y = playerPosition.Y;
float x = playerPosition.X;
playerPosition = new Vector2(x, y + 2);
}

if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Up))
{
float y = playerPosition.Y;
float x = playerPosition.X;
playerPosition = new Vector2(x, y - 2);
}

base.Update(gameTime);
}

Hit F5 again, and congratulations! You successfully displayed a 2D hardware accelerated sprite on the screen and enabled it to be moved up and down. This is a simple example, but hopefully you get an idea of how rapidly you can put together a simple game using XNA Game Develpopment Studio.

Labels: , , ,

Bookmark and Share

Friday, 13 March 2009

Will Visual Studio run on an Asus Eee 901 PC?

In a word, yes.

I've had an Asus Eee 901 PC for about six months now, and I love it as a web browsing platform, especially when combined with slickness of Google Chrome. But often, I'll want to tinker with a C# idea in the evening without slinking off to the study like some kind of social pariah. This got me thinking about whether the Eee could handle Visual Studio.




I opted for Visual Studio 2005 Express rather than 2008, and declined to install both MSDN and SQL Server Express. Installation itself is a task for the patient, as the Solid State Drive is not the fastest thing.

But once installed, it's very usable indeed. I wouldn't like to spend a lot of time writing code on a 1024x600 screen, but overall I think I can declare it a success - I was half-expecting it to wilt like a tulip in a themonuclear explosion.

It has also served to highlight how much I now rely on the new C# 3.0 syntax on a daily basis, though. Maybe I'll try and shoehorn 2008 on to the poor thing soon.

Labels: ,

Bookmark and Share

Friday, 27 February 2009

Visual Studio Tip of the Day

Here's something I found out today. If you put a comment in your code prefixed with "TODO:", like so:

//TODO: Implement Factory Pattern
Car C = new Car();

...it will subsequently appear in your Visual Studio Task List (View -> Task List) in the comments section:


Brilliant! Admitedly though, it's more like Tip of the Year since this is the first Tip of the Day on this blog. Hey, who's counting?

Labels:

Bookmark and Share

Monday, 23 February 2009

Visual Studio Fonts

Having reinstalled Visual Studio on one of my machines the other day, I was was at first thrown by the default font. Having now used Consolas for so long, Courier New just looked so wrong.

Compare, Courier New:

To Consolas:

Personally, I find Consolas a lot easier on the eye and nicer to read. Maybe it's because the curly brackets are that little bit more squiggly.

Even if you don't have Windows Vista or Windows 7, Consolas for Visual Studio 2005 and 2008 can be downloaded from Microsoft for free, here. One thing to bear in mind though, is that Consolas is a font designed to be used with ClearType switched ON. Switch it off, and it looks like this:


Not pretty, huh?

I can honestly say I'm sold as a satisfied Consolas customer, but if anyone uses anything different, I'd be interested to hear about it.

Subsequently realised, just about every man and their dog seems to have posted about this at some stage, but hey - maybe you're the one person who hasn't been converted to Consolas yet. This is for you.

Labels:

Bookmark and Share