Hi everyone [let's try this again since i forgot to put in the subject line the first time] first time poster here!

I am currently working on a 2d top down shooter game! Now, i have a light engine, just a Light class that deals with lighting tbh. The Light class gives light pretty much the same way Terraria does i.e. sort of floods areas with light. Now, what i want to add is for the lights to fade in *done* when created and fade out when its parent (an Entity) is destroyed. The problem is that my the parent in my Light class never is read as null after beeing set to null in my GameState class. It's structured a little bit like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| public class Light { private Entity parent;
public void Light(Entity parent) { this.parent = parent; }
public void update(long delta) { if(parent==null) { } }
public boolean isFlagged() { } }
public class GameState { private ArrayList<Entity> entities = new ArrayList<Entity>(); private ArrayList<Light> lights = new ArrayList<Light>();
public void update(long delta) { for(int i=0;i<entities.size();i++) { Entitiy e = entities.get(i); if(e.isFlagged()) { entities.remove(i); e = null; } e.update(delta); }
for(int i=0;i<lights.size();i++) { Light l = lights.get(i); if(l.isFlagged()) { lights.remove(i); l = null; } l.update(delta); } } } |
(I guess Light.parent isnt really a parent since it doesnt extend Entity, but no matter that for now.) So again, my problem is that if(parent==null) is never true even tho im positive i set the object that is the parent in ArrayList<Entity> entities to null. This appears as strange behaviour to me since i run the game with moving entities and the light follows the properly by reference to Light.parent.

Is there a better way to see if the Entity light is following is destroyed or not?
I hope this makes sense to you and someone can explain why this behaviour is nothing strange at all

If not I'll be happy to provide more details about the project and classes. Thanks!