Probably incredibly stupid question regarding Text (how to remove graphics?)


(Mike Evmm) #1

I’m used to adding labels and such (Text instances) directly to my world when an entity is not required, using addGraphic(myText). However, there doesn’t seem to be a way to remove it. removeAll() takes care of that, but it removes every other entity in stage as well, which is not at all practical. I’ve googled, and “flashpunk remove graphic” seems to redirect me to a bunch of tutorials and the Graphiclist doc. page. Am I missing something?
Mike


Also, what happened to the lounge? (shhhh)


(Jacob Albano) #2

Ultimately, in order to remove an entity added with AddGraphic, you’ll have to have a reference to the parent of the graphic you added. You can store it, like this:

var graphicOwner:Entity = world.addGraphic(...);

//  and later...

world.remove(graphicOwner);

Or you can give each one a unique name and remove it that way:

world.addGraphic(...).name = "lifeCount"

//  and later...

world.remove(world.getInstance("lifeCount"));

The first one is much faster, but the second might be more convenient.


(Mike Evmm) #3

Oh! Thanks! (I kept getting an error for trying to remove the Text instance directly with remove, never had thought of actually referencing the addGraphic itself!)