C# struct with an array
Posted
by Whitey
on Stack Overflow
See other posts from Stack Overflow
or by Whitey
Published on 2010-05-10T16:38:55Z
Indexed on
2010/05/10
16:44 UTC
Read the original article
Hit count: 189
I am making a game using C# with the XNA framework. The player is a 2D soldier on screen and the user is able to fire bullets. The bullets are stored in an array. I have looked into using Lists and arrays for this and I came to the conclusion that an array is a lot better for me, as there will be a lot of bullets firing and being destroyed at once, something that I read Lists don't handle so well.
After reading through some posts on the XNA forums, this came to my attention: http://forums.xna.com/forums/p/16037/84353.aspx
I have created a struct like so:
// Bullets
struct Bullet
{
Vector2 Position;
Vector2 Velocity;
float Rotation;
Rectangle BoundingRect;
bool Active;
}
And I made the array like this:
Bullet[] bulletCollection = new Bullet[100];
But when I try to do some code like this:
// Fire bullet
if (mouseState.LeftButton == ButtonState.Pressed)
{
for (int i = 0; i < bulletCollection.Length; i++)
{
if (!bulletCollection[i].Active)
{
// something
}
}
I get the following error:
'Zombie_Apocalypse.Game1.Bullet.Active' is inaccessible due to its protection level
Can anyone lend a hand? I have no idea why this error is popping up, or even if I'm declaring the array properly or anything... as the post on the XNA forums doesn't go into detail about that.
Thank you for any help you can provide. :)
© Stack Overflow or respective owner