Jump to content

Removing sprite from group messes up index returned from forEachAlive


Recommended Posts

I have a function 'checkHit' that calls..


..where "this" in this case is a extended Group object.


I do a check if enemies are hit when this is called (inside calculateHit), and if I hit an enemy that enemy is removed from the group.


The problem then seems to be that since the enemy is removed, the iteration through all the enemies alive fails when it comes to the end - it looks for the last index but there is one index less now in the group.


So I get this error:

Uncaught TypeError: Cannot read property 'alive' of undefined 

Is my design fundamentally flawed initially, or should the Group function forEachAlive check for undefined first?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...