What happens FIRST when i remove an entity


(Bora Kasap) #1

I have a real trouble about that. When i work with entities in complex functions there is problem about checking for is an Entity signed for removing or not.

This one doesn’t work instant

if(entity.world != null)

So i’m always putting another variable to base Entity class

public var _removed:Boolean = false;

Then everything perfectly works when i use this variable to check is it removed or not, but i have to use 2 lines to remove an entity in this way

this.world.remove(otherentity);
otherentity._removed = true;

that works instantly and i’ve no trouble anymore because i’m checking _removed for any entity to be sure it is not removed.

But, i want to learn “standart” way to solve this problem in Flashpunk, can you help me?


(Bora Kasap) #2

i got an idea right now. is that the solution?

this.world.remove(this);
this.world.updateLists();

???


(Jacob Albano) #3

I strongly recommend you don’t do that.

There’s no standard way in Flashpunk to check if an entity is about to be removed, so your solution is as close as you’re going to get. I’d personally put it on a custom base class rather than modifying FP, though.

public class AlobarEntity extends Entity
{
    public function get markedForRemoval():Boolean { return _removal; }
    private var _removal:Boolean;

    public function AlobarEntity(x:Number = 0, y:Number = 0, graphic:Graphic = null, mask:Mask = null)
    {
        super(x, y, graphic, mask);
    }

    public function markForRemoval():void
    {
        markedForRemoval = true;
        world.remove(this);
    }
}

(Zachary Lewis) #4

You shouldn’t need to call updateLists() ever. Why do you need to check if it was removed? Maybe there’s a design issue that can be fixed.


(Bora Kasap) #5

You may be right, i’m working on a new game with better wisdom and i didn’t need to do that until now. So, i’m gonna write here if i encounter same problem again.