1 2 3 4 5 6 7 8 | window.onkeydown = function (e) { var key = e.keyCode; ... if (key === 74) { // 'j' runner.jump(); } }; |
1 2 3 4 5 6 7 8 9 | SnailBait.prototype = { ... start: function () { this.createSprites(); this.initializeImages(); this.equipRunner(); this.splashToast('Good Luck!'); }, }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | SnailBait.prototype = { equipRunner: function () { // This function sets runner attributes: this.runner.jumping = false; // 'this' is snailBait this.runner.track = this.INITIAL_RUNNER_TRACK; ... // More runner attributes omitted for brevity // This function also implements the runner's jump() method: this.runner.jump = function () { if ( ! this.jumping) { // 'this' is the runner. this.jumping = true; // Start the jump } }; }, }, |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | var SnailBait = function () { ... this.jumpBehavior = { execute: function(sprite, time, fps) { // Implement jumping here }, ... }; ... this.runner = new Sprite('runner', // type this.runnerArtist, // artist [ this.runBehavior, // behaviors this.jumpBehavior, this.fallBehavior ]); ... }; |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |