Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

100 Neutral

About BomberJacket

  • Rank
  1. BomberJacket

    [XNA] Too Many Sprites?

    Yeah, it shows up in the Output window after the startup messages finish. By default that won't show up in the editor unless the game is running, so you have to enable it if you want to check it afterwards. Can't remember off the top of my head exactly which checkbox you need to hit, but Google will give you an answer there. @Way2Lazy2Care For now, Destroy is only called in Projectiles when they exceed the screen's bounds. Create is mostly a fancy wrapper for Game.AddObject, so if I "Create" something from Game, I'll use AddObject instead. That said, Game calls AddObject on Ship at the start, and Ship calls Create on Projectiles to fire its weapon. Could you elaborate more on the existing reference you mention? If it's a problem, it's one I'd prefer to deal with when I'm not working on other facets of the game.
  2. BomberJacket

    [XNA] Too Many Sprites?

    Finally figured out an easy fix. Implemented IDisposable on GameObject and call Dispose() right after removing object from arrays. Probably not as elegant as a resource pool, but I can't guarantee all projectiles will be identical in the future. Regardless, my ship can now repeatedly fire 300 projectiles a second without crashing the game after any period of time (although with tremendous slowdown if firing from the bottom of the screen). Thanks to everyone who helped, I really appreciate it. Moral of the story: IDisposable is your friend. Well, sometimes anyway.
  3. BomberJacket

    [XNA] Too Many Sprites?

    Added Destructors to my custom classes to see if they were being called. They weren't. I wonder why GC isn't kicking in.
  4. BomberJacket

    [XNA] Too Many Sprites?

    OK wow, this is apparently a memory issue. I waited after the shot sprites stopped drawing and then the screen started flickering and the ship disappeared. Then the whole thing crashed and I got an out of memory error. I guess things are being created faster than they're being released? Here's a few code samples. I'm deriving most things that are drawn in the scene from a parent class called GameObject. GameObject derives from DrawableGameComponent. So, in my Game file, I just use Components.Add on whatever GameObject I want to add and add the object to an array of GameObjects to check collisions en masse (if two objects collide, they each call a function in GameObject called OnCollision). I wanted to simplify things, so everytime I add/remove a GameObject to the scene, I do it through the Game.AddObject and Game.RemoveObject (Game has a static instance so the GameObjects themselves can call these as well, mostly to properly destroy themselves). I'm posting all the code related to creating and deleting GameObjects. I'm guessing something isn't being removed from an array or something, but I'm at a loss as to where. Game.cs public void AddObject(GameObject objToAdd) { spriteCounter++; Console.WriteLine(spriteCounter); gameObjects.Add(objToAdd); Components.Add(objToAdd); } public void RemoveObject(GameObject objToRemove) { spriteCounter--; Console.WriteLine(spriteCounter); gameObjects.Remove(objToRemove); Components.Remove(objToRemove); } GameObject.cs public virtual void Create(GameObject toCreate, int newDrawOrder = 5) { toCreate.DrawOrder = newDrawOrder; Game.instance.AddObject(toCreate); } public virtual void Destroy(GameObject toDestroy, bool loudDeath = true) { if (loudDeath) OnDeath(); Game.instance.RemoveObject(toDestroy); }
  5. BomberJacket

    [XNA] Too Many Sprites?

    @EJH Thanks, I'll take a look at this later. Seems like an approach that could work well, although not all of these Projectiles are going to have the same behavior or sprite. @way2lazy2care Will post some code when I get home. I'm adding the Projectiles individually as Components, and each one has its own Draw call. @JSelf No, just 1700 total. The ones that go off the screen get removed from Components, so their Draw loops shouldn't be called anymore. When it hits 1700, I hit the Fire key and the Log says that Projectiles are being created, but I don't see any being drawn on the screen. Thanks for the all the responses!
  6. BomberJacket

    [XNA] Too Many Sprites?

    Thanks for the advice. @Moonkis Reusing bullets sounds good, although I plan on having bullets with various properties on them. Will see how this pans out @falocn93 I am removing bullets that travel outside the screen dimensions, although again, C#'s garbage collection doesn't seem to be kicking in before the sprite limit is reached. One thing I forgot to add is that I'm adding bullets in as Components. Maybe there's a certain way I have to remove them?
  7. So, I've picked up XNA again after a long time with Unity, and I've run into an interesting problem. I'm doing a Shmup, and after roughly 1700 shots, the sprites for them are no longer being drawn. There's no warning messages, nothing in the console to indicate that something's gone wrong. I'm really at a loss as to what's going on here, though I've got an inkling that it has to do with the previous sprites not being properly destroyed. And given that its a shmup, "use fewer sprites" really isn't going to be an option. Has anyone else had this problem or know what might be causing it? I've tried a few things already. The best idea seemed to be to use SpriteBatch.Dispose, but no matter where I put it or how I set things up it seems to always crash my game.
  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!