Removing gems

We now have a list of gems to be removed, so it's time to remove them from the game.

The idea: Scan through the gemsToRemove array and remove all the gems.

The development: Removing a gem takes two steps: removing the gem DisplayObject from Display List, and update jewels array. This leads to a question: if jewels array contains element from 0 to 6 to represent different gem types, how can we code the "empty" status? We'll use -1 to say there isn't any gem in the jewels array.

The first thing to do is looping through the gemsToRemove array, and we'll do it using the forEach method as we did during the making of Astro-Panic! although we used it on a Vector.

Indeed, forEach method works in the same way with arrays too. Add this line ...

Get Flash Game Development by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.