Game Development Reference
In-Depth Information
Adding the Buttons to MainScene
If you want to see the new logo and buttons in the game, you still have to add the
MainMenuButtons.ccb to the MainScene.ccb . Do so as described earlier for the
MainMenuBackground.ccb by either dragging the .ccb file itself onto the MainScene.ccb
stage or by dragging it from the Tileless Editor View.
Either way, you should change the new CCBFile node's position to 0,0 and give it a prop-
er nameā€”for instance, logoAndButtons .
Creating Buttons Out of Ordinary Sprites
Hmmm, isn't there something amiss? So far the buttons aren't really buttons, just a sprite
with a label. How do you make them click?
Easy, by adding a button! And then removing the button's frame and label so that it's just
an invisible touch area that runs a selector. The only downside is that you can't animate
the button's highlighted state because there's no notification sent by the button when it's
merely highlighted. But at least you'll have a way to create buttons without having to
make the images play by the rules of the Button node.
Note Try using play.png or settings.png as the button's normal-state sprite
frame and you'll know what I mean by said rules. Or create a Sprite 9 Slice and
assign it the SpriteSheets/Menu/play.png. Internally, the Button node uses a
Sprite 9 Slice, which is responsible for scaling the nine different regions of the
sprite, well, differently.
Open MainMenuButtons.ccb , and repeat the following steps for both the play and settings
sprites:
8.
Drag and drop a Button from the Node Library View onto the sprite
( play or settings ) in the timeline so the button becomes a child of
the sprite.
9.
Change the button's position types to % and the values to 50 to center
the button on the sprite.
10.
Clear the button's Title field on the Item Properties tab by removing
all characters. This makes the button's label disappear.
Search WWH ::




Custom Search