Game Development Reference
In-Depth Information
Figure 8-3.
Blocks falling into place (annoted with const identifiers)
Next, we add an
EventListener
for the
CustomEventClickBlock.EVENT_CLICK_BLOCK
event we
created earlier in the
CustomEventClickBlock
class. We will put into our
CustomEvent
class named
CUSTOMEVENT_CLICKBLOCK
. This is the same event that we had the
Block
class dispatch when it was
clicked. The function
blockClickListener
will be used to handle that event. Finally, we put the
Block
on the screen with
addChild
and then return a reference to the
Block
to the caller. In our case, this is
always
replaceBlocks
, which will store the reference in the
board
2D array.
tempBlock.x=(col*BLOCK_WIDTH)+X_PAD+(col*COL_SPACING);
tempBlock.y= 0 - BLOCK_HEIGHT;
tempBlock.addEventListener(CustomEventClickBlock.EVENT_CLICK_BLOCK,
blockClickListener, false, 0, true);
this.addChild(tempBlock);
return tempBlock;
}
Expanding update and render for ColorDrop
The
update
and
render
functions for Color Drop are similar to ones created for other games in
this topic. However, we have expanded the logic a bit in both of them to assist with our local
ColorDrop
state machine. Recall, that these two functions are called regardless of the
gameState
.
We do this because multiple states require these functions to be called, but it is messy to call
them multiple times within the state
switch
statement. Instead, we put in some simple logic to test
the
Block
objects to see if they need to have their
render
or
update
functions called.