AS3 game running slow (many objects)

ok so I am creating a tower defense game.I was wondering how do i remove objects that I do not require anymore (i.e lets say a bullet object has hit a target, at the moment all im going is setting the object to invisible). Starts to get slow after about 1.5K objects.

I have done a bit of research, however their doesn't seem to be any ubiquitous method. What do you guys recommend.

thanks

Answers


You need to remove the object from the stage, and ensure all references to it are set to removed. This includes removing event listeners, child display objects and stopping the execution of any internal code. Then the objects will become eligible for garbage collection.

So for example:

if(myBullet has hit tower) {
    removeChild(myBullet);
    myBullet.removeEventLister(someEvent, someFunction);
    myBullet.stopSpinning();
    myBullet = null;
}

Need Your Help

How can I use ViewPager to display apps?

java android gridview android-fragments android-viewpager

As the title states, how exactly can I use ViewPager to display a list of apps. Right now I'm using a GridView to display the list of apps on my device and it runs the app upon selection. However I...

Upload Jruby on rails on Google App Engine - cannot find gem appengine-rack

google-app-engine gem jrubyonrails

Just trying to deploy a simple Jruby on rails app on Google App Engine but falling at first hurdle.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.