panthro
panthro

Reputation: 24069

AS3 adding and removing objects, is it a good idea?

In AS3 I create a number of playing cards through a class that extends a sprite.

I then add and remove these to stage throughout the game.

I was wondering, is this the right way to do it? Is it processor intensive to keep adding and removing objects?

Upvotes: 1

Views: 142

Answers (1)

Simon Forsberg
Simon Forsberg

Reputation: 13351

I suppose that when you say "adding and removing objects" you mean adding and removing to/from the stage.

It is more processor intensive to create and destroy the objects over and over than to add and remove to/from the stage. So I'd say that you're safe.

However, an alternative to adding and removing to the stage is to change the visible propety of your sprites. This is even less processor intensive and could be a suitable solution for you. Note that when an object is invisible, it's still there. It just doesn't show. See this question on StackOverflow: visible property of DisplayObject

Upvotes: 1

Related Questions