Game Development Reference
In-Depth Information
Figure 5-13. Cloning a container
One thing you'll notice, unlike the text-cloning example, is that you pass in the value of true to the clone method.
This is so it will be executed in recursive mode, which will clone all children within the container, as well as its
children's children. To duplicate all objects in your container, be sure to pass this value in when using clone .
Now that you've learned how to group and manipulate display objects into containers, it's time to put them into
a game. A great example for the use of containers in games is when using them for creating playing cards. Let's do that
now in the next exercise, which will demonstrate the true power in containers.
Veggie Match
Veggie Match is a simple memory game where the player tries to match cards by revealing them two at a time.
Preload images needed to build card containers.
Container , and add a card shell, card back, food graphic, and a text object.
Build cards using
Apply a drop shadow to each card object.
Flip each card on click by hiding the
back bitmap in the container.
Flip back over if guessed wrong by revealing the card's
back bitmap.
End the game when all cards are successfully flipped over.
Setting Up the Game Files
First, set up the HTML document that includes a canvas element and the necessary CreateJS file includes
(see Listing 5-22). The game code will be written in a separate file and named memory.js . Be sure to create this
file and include it in the document.
 
Search WWH ::




Custom Search