Game Development Reference
In-Depth Information
Figure 4-7. Combo and Free Player text animations
This loop is still not quite complete. The brick needs to be removed from the stage so it will disappear when it is
next updated. Setting these busted bricks to null helps keep the game clean, and invokes garbage collection on objects
no longer in use. It's also important to splice this object out of the bricks array so it's no longer factored in this loop
during the next update cycle.
At last, the puck's y velocity is reversed and the loop is broken. You only need to detect one brick collision per
update cycle, so breaking the loop prevents unnecessary code execution.
Rendering the Game Elements
The puck's and paddle's next positions have been calculated, and the fate of each brick has been determined. All
points and lives have been properly added or subtracted from the game. Now it's finally time to officially assign these
new properties to these display objects (see Listing 4-18), which will take effect once the stage is updated.
Listing 4-18. The Render Cycle
function render() {
paddle.x = paddle.nextX;
puck.x = puck.nextX;
puck.y = puck.nextY;
 
Search WWH ::




Custom Search