XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

Integrating 2D Particle system with GameStateManagement

Last post 10/15/2009 6:11 AM by Wonder Cheese. 5 replies.
  • 10/12/2009 10:46 PM

    Integrating 2D Particle system with GameStateManagement

    I know this is a question that has been discussed here before, but in all my searches, I haven't found a solution.

    I got a particle system (from here) to work with my game.  I got my game (without the particle system) to work within the GameStateManagement sample.  I have been trying to add the particle system back into my game within the GameStateManagement sample, but am having issues.

    So far, I have not actually tried to create any explosions in the game, I've just been trying to add in the classes needed for the particle system.  Those include ExplosionParticleSystem.cs, ExplosionSmokeParticleSystem.cs, Particle.cs, and ParticleSystem.cs.  I have not changed anything in those files other than changing the namespace to "GameStateManagement" and changing lines like "private Game1 game" to "private GameStateManagementGame game".

    The errors I'm currently getting come from the "Draw" method in ParticleSystem.cs.
    public override void Draw(GameTime gameTime) 
                { 
                    game.SpriteBatch.Begin(spriteBlendMode); 

    The error is
    Error    1    'GameStateManagement.GameStateManagementGame' does not contain a definition for 'SpriteBatch' and no extension method 'SpriteBatch' accepting a first argument of type 'GameStateManagement.GameStateManagementGame' could be found (are you missing a using directive or an assembly reference?)

    I've tried changing the above line to
    "SpriteBatch spriteBatch = ScreenManager.SpriteBatch;"
    which doesn't work either.

    I've uploaded the source code here.
    I'd really appreciate suggestions on the best way to get this working.  Thanks!
  • 10/12/2009 11:59 PM In reply to

    Re: Integrating 2D Particle system with GameStateManagement

    If you look at the ParticleSampleGame, you will see that it has a public SpriteBatch property. You will need to either add that same SpriteBatch property to your GameStateManagementGame class, or you could change the ParticleSystem class to get a SpriteBatch in some other way (perhaps it could just create one of its own for instance).
    XNA Framework Developer - blog - homepage
  • 10/13/2009 1:54 AM In reply to

    Re: Integrating 2D Particle system with GameStateManagement

    Thanks for the advice.  I took the first option you gave, and that cleared up the issue I was having.  I also added
    ParticleSystem explosion;
    ParticleSystem smoke;
    to public class GameplayScreen : GameScreen

    My GameplayScreen constructor now looks like this:
    public GameplayScreen() 
            { 
                TransitionOnTime = TimeSpan.FromSeconds(1.5); 
                TransitionOffTime = TimeSpan.FromSeconds(0.5); 
                explosion = new ExplosionParticleSystem(this, 1, "Sprites\\explosion"); 
                smoke = new ExplosionSmokeParticleSystem(this, 2, "Sprites\\smoke"); 
                Components.Add(smoke); 
                Components.Add(explosion); 
                 
            } 

    but that is causing problems, I'm assuming that it's from the "this" portion.

    Error    1    The best overloaded method match for 'GameStateManagement.Particles.ExplosionParticleSystem.ExplosionParticleSystem(GameStateManagement.GameStateManagementGame, int, string)' has some invalid arguments   

    and

    Error    2    Argument '1': cannot convert from 'GameStateManagement.GameplayScreen' to 'GameStateManagement.GameStateManagementGame'   

    It's also having problems with the Components.Add portions, but I figure I'll deal with that when I figure out the first 2 errors.  Thanks again for any help.
  • 10/13/2009 2:14 AM In reply to

    Re: Integrating 2D Particle system with GameStateManagement

    I got rid of those errors by changing the constructor like this:
    public GameplayScreen(GameStateManagementGame game) 
            { 
                TransitionOnTime = TimeSpan.FromSeconds(1.5); 
                TransitionOffTime = TimeSpan.FromSeconds(0.5); 
                explosion = new ExplosionParticleSystem(game, 1, "Sprites\\explosion"); 
                smoke = new ExplosionSmokeParticleSystem(game, 2, "Sprites\\smoke"); 
                Components.Add(smoke); 
                Components.Add(explosion); 
                 
            } 

    so that issue seems to be cleared up, now trying to figure out this problem:
    Error    1    The name 'Components' does not exist in the current context
  • 10/13/2009 2:46 PM In reply to

    Re: Integrating 2D Particle system with GameStateManagement

    I made some further changes and have eliminated all errors.  The game runs fine, however, no actual smoke or explosions occur when the player's ship hits an asteroid.  Shawn (or anyone else), if you have the time, do you think you could look at my code and see where I'm going wrong here?  I've gotten so hung up on this particle system issue that I'm starting to feel like I should have found a simpler solution.  I'd appreciate it greatly if someone could look this over and give me some advice.

    I uploaded the current version here

    Thanks again for any assistance.
  • 10/15/2009 6:11 AM In reply to

    Re: Integrating 2D Particle system with GameStateManagement

    Anyone willing to give this a look?  I'd deeply appreciate it.
Page 1 of 1 (6 items) Previous Next