Jump to content
  • Advertisement
Sign in to follow this  
Tim Ogunmakin

[Solved] Loading enemies method

This topic is 2003 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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--;                        }                    }                }


"enemies.Add(new EnemySpawn(Content.Load("Graphics/Sprites/enemy"), new Vector2(1100, randY)));"

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 this post


Link to post
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:

 

heirarchy.png

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!