## Recommended Posts

I'm trying to spawn a new enemy in my game, I've been following a book to do this :

public void LoadEnemies()                {                    int randY = random.Next(100,400);                    if (spawnzz >= 1)                    {                        spawnzz = 0;                        if (enemies.Count < 4)                        {                            enemies.Add(new EnemySpawn(Content.Load("Graphics/Sprites/enemy"), new Vector2(1100, randY)));                        }                    }                    for (int i = 0; i < enemies.Count; i++)                    {                        if (!enemies[i].isVisible)                        {                            enemies.RemoveAt(i);                            i--;                        }                    }                }

The part there it says Content.Load is where it comes up in red and displays "The name content does not exist in current context"

Help!

Regards,
Tim

##### Share on other sites

Oh!  my bad,  that function either needs to sit in the Game1 class, (where you will find the Content object) or, you need to somehow expose the Content object.

##### Share on other sites
It's hard to help you with the information you shared, what does the "The name content does not exist in current context" error message mean for example? Is it because the file wasn't found? I Assume that Graphics/Sprites/enemy is suppose to be a path to a file but it seems to be missing what format the file has.

edit:
Seems like I missunderstood the question! Edited by simpler

##### Share on other sites
Oh!  my bad,  that function either needs to sit in the Game1 class, (where you will find the Content object) or, you need to somehow expose the Content object.

I dont have a Game1 function, most of my code is in the GameplayScreen class, here is my heirarchy:

##### Share on other sites
I'm refering to the "Class" called game.cs.  It's in the picture as well.  Essentially, your code is asking for an object called "Content", Content exists in the Game.cs class, which inside is usually named Game1.

This function for loading enemies needs to be inside the Game1 class, or the Content object needs to be exposed to the other class some how.

##### Share on other sites

Also, what is the book you are using.  They are having you repetitively load an image during game play.  That's typically a bad idea, as it is faster to load it once in to a variable, and then reuse it as you need.

##### Share on other sites
I'm refering to the "Class" called game.cs.  It's in the picture as well.  Essentially, your code is asking for an object called "Content", Content exists in the Game.cs class, which inside is usually named Game1.

This function for loading enemies needs to be inside the Game1 class, or the Content object needs to be exposed to the other class some how.

Ive now done this, I've moved the loading enemies into the Game class in the LoadContent() region however I'm getting the same thing :S

Also, what is the book you are using.  They are having you repetitively load an image during game play.  That's typically a bad idea, as it is faster to load it once in to a variable, and then reuse it as you need.

Im using "Learning XNA 4.0" by Aaron reed :)

##### Share on other sites

Fixed it all by re-doing the whole spawning code myself. Note to self: try something first before looking at books to do it

thanks for the help!

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628301
• Total Posts
2981906

• 9
• 11
• 11
• 10
• 10