Jump to content

  • Log In with Google      Sign In   
  • Create Account

[Solved] Loading enemies method


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Tubbly   Members   -  Reputation: 107

Like
0Likes
Like

Posted 27 December 2012 - 11:42 AM

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



Sponsor:

#2 Dan Violet Sagmiller   Members   -  Reputation: 896

Like
1Likes
Like

Posted 27 December 2012 - 12:34 PM

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.


Moltar - "Do you even know how to use that?"

Space Ghost - “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer."

Dan - "Best Description of AI ever."

My Game(s), Warp Wars is in early development and can be found here: http://blog.WarpWars.Net.


#3 simpler   Members   -  Reputation: 913

Like
0Likes
Like

Posted 27 December 2012 - 12:35 PM

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, 27 December 2012 - 12:38 PM.


#4 Tubbly   Members   -  Reputation: 107

Like
0Likes
Like

Posted 27 December 2012 - 01:11 PM

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



#5 Dan Violet Sagmiller   Members   -  Reputation: 896

Like
1Likes
Like

Posted 27 December 2012 - 01:44 PM

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.  

Moltar - "Do you even know how to use that?"

Space Ghost - “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer."

Dan - "Best Description of AI ever."

My Game(s), Warp Wars is in early development and can be found here: http://blog.WarpWars.Net.


#6 Dan Violet Sagmiller   Members   -  Reputation: 896

Like
0Likes
Like

Posted 27 December 2012 - 01:46 PM

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.


Moltar - "Do you even know how to use that?"

Space Ghost - “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer."

Dan - "Best Description of AI ever."

My Game(s), Warp Wars is in early development and can be found here: http://blog.WarpWars.Net.


#7 Tubbly   Members   -  Reputation: 107

Like
0Likes
Like

Posted 28 December 2012 - 02:09 PM

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 :)



#8 Tubbly   Members   -  Reputation: 107

Like
0Likes
Like

Posted 28 December 2012 - 06:26 PM

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!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS