Sign in to follow this  
Dieseltjuh

[.net] [XNA] How to ? (remove sprites)

Recommended Posts

Hi all, i've got a question regarding to a 2d game im making... i've got this sprite which is "killed" at some point in my code, but i cant seem to find a way to remove the prite from the spritebatch... (im using XNA refresh 1.0) if any1 can help me, its gladly appreciated :) if you need more info, feel free to ask and ill post it :) Thanks in advance, Dieseltjuh.

Share this post


Link to post
Share on other sites
I'm not sure I understand your question. As far as I can tell, to draw a sprite you call SpriteBatch.Draw(), so if you no longer want to draw a particular sprite, just don't call Draw() for it.

Share this post


Link to post
Share on other sites
First off, I'd recommend upgrading to XNA GS 2.0 (or possibly the 3.0 CTP). Second, how are you drawing the sprites? If you have a List<Texture2D> or some such, just remove that sprite from the list. The SpriteBatch class only draws what you tell it to, it doesn't maintain a list of things to draw.

Share this post


Link to post
Share on other sites
and what's the big benefit for going to 2.0?

i made my game in 1.0 so im keeping it in 1.0 until its finished (because ill only run into errors because i dont know 2.0 yet), and then ill start on 3.0 if its out probbably.

Share this post


Link to post
Share on other sites
Quote:
Original post by Dieseltjuh
and what's the big benefit for going to 2.0?

i made my game in 1.0 so im keeping it in 1.0 until its finished (because ill only run into errors because i dont know 2.0 yet), and then ill start on 3.0 if its out probbably.


Its likely that the structure change in 2.0 won't be that different unless you're doing some more complex tasks which it sounds like you are not. 2.0 offers just stuff along with much more fine-tuned and better functioning components. I highly recommend upgrading if you plan on spending more time with XNA. Even if you're almost done with your current project or don't need XNA 2.0, it will still help you learn it.

SpriteBatch will only draw what you tell it to Draw() between Begin() and End() (at least I believe thats the name of the methods). As mentioned, to not draw something, just don't call Draw() on it that frame.

Share this post


Link to post
Share on other sites
Quote:
Original post by Dieseltjuh
on the begginer help forum i made the same post :x but as you can see there, i used List<texture2D>("filepath");


In theory then, when your cycling through your list of objects and run across one that is 'killed', you need to remove it from your list. You should be able to do something like object.remove() to remove it from the list while your going through it, then once removed spritebatch wont display it anymore.

As far as upgrading to 2.0 or even 3.0, I would hold off on 3.0 or at least dont try converting your code.. Just create a new project in 3.0 and add in your files, content, etc. 3.0 adds the media namespace so you can play mp3, wav and wma files directly from your content directory rather than having to add them in through XACT.. So thats the biggest plus..

As far as actual structure changes, a few minor things were changed but nothing thats going to make you really have to 'relearn'.. LoadAllContent was changed a bit, a content project was added for you by default, etc..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this