• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
menyo

Enemy is dead, now what?

3 posts in this topic

So i tried looking everywhere for a solid answer for this but there is a lot of contradiction and since i have my own possibly wrong thoughts makes this very confusing.

This pretty much goes for any object i dont use anymore but let's take the enemy object. What should i do exactly if health drops below 0?

Obviously i can put it out of my list, it does not get updated or drawn anymore, but is it still in memory?

Some say this is enough, i doubt this.

Some say i have to null it so the garbage collector takes it on its next run.

Some say i have to make it inherit IDisposable and dispose of it manually.

So what is a good way to handle objects that you wont be using anymore?
0

Share this post


Link to post
Share on other sites
Allocating/Deallocating memory is a pretty expensive thing to do. However, with C# the garbage collector is going to decide what to end up doing with your memory once there are no longer any references to it. It still isn't a good idea to give the garbage collector any excuse to start up and begin sifting through your 'trash'.

Ideally, instead of 'deleting' the enemy once it's dead, have your enemies have a bool variable saying whether they're active or not. If the enemy is dead, it isn't active. If the enemy isn't active then you can skip physics, rendering, etc... on that particular enemy during your update loop.

Then, when you want to spawn new enemies, you can flag the deactivated enemy as active again and re-initialize the enemy to default stats (back to full health, etc...).

It's a bit of a balancing act though since it's not really practical to have everything in your game pre-allocated and always sitting in memory. If you're going to be creating/deleting something quite often, however, you should focus on keeping that in memory as long as possible otherwise you're going to be making your garbage collector work overtime.
1

Share this post


Link to post
Share on other sites
Basically, remove all reference to the object you wish to disappear. It will then do so... eventually.

See [url="http://msdn.microsoft.com/en-us/library/ms973837.aspx"]Garbage Collector Basics[/url].

For something like enemies, however, you might want to consider a different solution. I don't mean to add to the pile of answers you've already gotten but I'm going to go ahead and add to the pile of answers you've already gotten:

If you find yourself creating and destroying enemies pretty rapidly (conceptually not hard to imagine on my part). Consider creating a pool of enemies of some large-enough size to hold all the enemies that can be on the screen at one time + some margin of error. Then, any time you need an enemy, grab something from that pool, initialize it as a new enemy, and use it until you no longer need it. Once it is killed, return it to the enemy pool to be used again. These don't depend on the garbage collector so you don't find yourself in this strange position of wondering if they're "truly" dead. They're not, but that ends up being a good thing.
1

Share this post


Link to post
Share on other sites
Ok great, so essentially once i create an enemy and only reference that from a list it does get cleaned up eventually once kicked out of the list.

Very good idea to keep a list as a pool, just flag a bool for the status of the enemy and stop interacting with those. Once a new enemy gets created i use one of the free spots or one with the dead flag.

Thanks for the link, i'll read it. I believe Shawn has created one in his blog too, guess i am going to read that too.
0

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  
Followers 0