Remove display object from group

Hi, 

I want make sure I do things right.

My question:

Should I nil entry (see code below) in display group after removed display object from it? 

for i=layers.lasers.numChildren, 1, -1 do &nbsp; &nbsp; &nbsp; laser = layers.lasers[i] &nbsp; &nbsp; &nbsp; -- Check if laser goes out of the screen &nbsp; &nbsp; &nbsp; if not laser:offScreen() then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;laser:update( dt ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for j=layers.asteroids.numChildren, 1, -1 do &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; asteroid = layers.asteroids[j] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- Detect collision &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if laser:hit( asteroid ) then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;... &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;asteroid:removeSelf() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--layers.asteroids[j] = nil \<-- this line &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- Remove laser &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;laser:removeSelf() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--layers.lasers[j] = nil&nbsp;&nbsp;\<-- this line&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end&nbsp; &nbsp; &nbsp; &nbsp; else &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- Remove laser &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;laser:removeSelf() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--layers.lasers[i] = nil&nbsp;&nbsp;\<-- this line &nbsp; &nbsp; &nbsp; end&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end

ldurniat

OK.  I’ve read it again.

I see some issues.

  1. I say this all the time, but… don’t use obj:removeSelf()  use display.remove( obj ) instead. It is way safer.

  2. When you remove objects from a  display group, you DO NOT need to nil the entry.

I have seen this advice from you often:) I replace old instruction with new ones.

Ok:)

Thanks for fast reply :slight_smile:

OK.  I’ve read it again.

I see some issues.

  1. I say this all the time, but… don’t use obj:removeSelf()  use display.remove( obj ) instead. It is way safer.

  2. When you remove objects from a  display group, you DO NOT need to nil the entry.

I have seen this advice from you often:) I replace old instruction with new ones.

Ok:)

Thanks for fast reply :slight_smile: