HTML5 Game Development: Adding Buttons with the GameButton Object
If your game only allows keyboard input, users with touchscreen devices may not be able to play. Use the gameButton object to add touchscreen-supported buttons.
|buttonName = new
|Creates a GameButton object called
buttonName displaying the label value.
The label value can include HTML code for more interesting
|setPosition(x,y)||Sets the button’s upper-left corner to the indicated (x,y) coordinates. The coordinates are for the
page, so buttons can be placed on the game scene or elsewhere on
|setSize(width, height)||Changes the button’s size. You may need to experiment to find
the optimal button size for easy play without obscuring the
|isClicked()||Returns true if the button is currently clicked and false if it
is not. Provides an easy way to read the button’s status in the