Grandy12 Posted August 23, 2015 Share Posted August 23, 2015 I have one function on update that is getting this enemy position.x So when I destroy() the enemy, the game crases, because "Cannot read property 'x' of null"; Link to comment Share on other sites More sharing options...
tips4design Posted August 23, 2015 Share Posted August 23, 2015 Well, if the enemy is dead why are you still trying to read it's position? Link to comment Share on other sites More sharing options...
Grandy12 Posted August 24, 2015 Author Share Posted August 24, 2015 Well, if the enemy is dead why are you still trying to read it's position? There's a function on update that keeps tabs of the position of all sprites inside the group called 'enemies', to simulate a behavior. Like, if their position.x is too far away from the player's position.x, they attempt to shorten the distance, or if it is too close, they try to back away. So it's not really me that wants to read its position, it's just that I told the game to keep reading it's position all the time. But your post gave me an idea, which worked. I just added another boolean to the sprite to check if it was dead or not, then I had that position checked stop checking any sprites where it was set true, and afterwards destroyed it. I mean, in retrospect that was pretty simple, and I feel rather silly. Thanks for helping my figure this out. Link to comment Share on other sites More sharing options...
drhayes Posted August 24, 2015 Share Posted August 24, 2015 I use "alive" on my sprites for this, if that helps. Link to comment Share on other sites More sharing options...
Recommended Posts