Game Development Reference
In-Depth Information
Figure 8-7. runningMan.png
Two functions are then called to create an instance of Runner and the buttons to control him (see Listing 8-23).
Listing 8-23. Using the Runner Class and Setting the Button Listeners
function buildRunner() {
runner = new sprites.Runner(spritesheet);
runner.y = 100;
stage.addChild(runner);
}
function buildButtons() {
var jumpBtn = new ui.SimpleButton("JUMP");
var runBtn = new ui.SimpleButton("RUN");
var idleBtn = new ui.SimpleButton("IDLE");
jumpBtn.on('click', function (e) {
runner.jump();
});
runBtn.on('click', function (e) {
runner.run();
});
runBtn.x = jumpBtn.width + 10;
idleBtn.on('click', function (e) {
runner.stand();
});
Search WWH ::




Custom Search