Neil Reed

XNA Turn Based Game Blog

Re-usable Game Components V1.0

7 Response to Re-usable Game Components V1.0

24 April 2010 at 18:14

Hey, thanks for releasing the game components, I'm having some issues using the bar part of it, mainly this bit...

Bar HP = new Bar();

I'm getting this error

'NeilsGameComponents.Bar' does not contain a constructor that takes '0' arguments

so what am I exactly ment to do to get the bar working?

I've only just started XNA coding about a week ago lol

25 April 2010 at 17:17

Hello Sgt,

You need to pass in a Graphics Device object for the constructor to work.

There is more documentation at:

http://www.neil.copperstream.co.uk/XNA/NeilsGameComponents/class_neils_game_components_1_1_bar.html

25 April 2010 at 17:48

As I said in my previous post, I've only been doing XNA for about a week or so, it's all so new to me, what exactly do I need to pass for the constructor? I've got something else in my coding for a graphics device...

public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}

do I pass graphics? or something else into it?

25 April 2010 at 19:44

Hi Sgt,

In that example you would pass in graphics.

graphics = new GraphicsDeviceManager(this);

Bar HP = new Bar(graphics);

I think I have a test app on one of my laptops.

The one that created the videos.

If you wish I can try and upload it tomorrow?

Did you download the code from http://moltione.codeplex.com?

If not that site has the source for the components.

Please note they are still very rough around the edges so I apologise in advance for any bugs!

P.S It might also be worthwhile checking out the tutorials on the Microsoft XNA site.

Regards,

Neil

25 April 2010 at 20:23

Yeah I downloaded the source code to see exactly what it was expecting, I did what you suggested but it threw another error

The best overloaded method match for 'NeilsGameComponents.Bar.Bar(Microsoft.Xna.Framework.Graphics.GraphicsDevice)' has some invalid arguments

public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
SpriteFont font;
Counter healthbar = new Counter();
Bar HP = new Bar(graphics); <- the line that through the error, i hope I'm doing it right lol, I would love to get a health bar working.

26 April 2010 at 07:50

I have got the source code infront of me now and you need to call new bar via:

Bar HP = new Bar(graphics.GraphicsDevice);

I have also uploaded my test app:

http://www.neil.copperstream.co.uk/XNA/ComponentsTest.zip

26 April 2010 at 10:33

Thanks, I compared my source to the testing source and figured out why it wasn't working, it's all working now :)

Took me a while to figure out how to set the borders width, but I got there.

Now I'm trying to figure out the event handlers for AtMinValue, so I can have him lose a life, or die if he has no more lives.