1 2 3 4 5 6 7 8 9 10 11 12 13 14 | var SnailBait = function () { ... this.fallBehavior = { pause: function (sprite) { sprite.fallAnimationTimer.pause(); }, unpause: function (sprite) { sprite.fallAnimationTimer.unpause(); }, } ... } |
1 2 3 4 5 6 7 8 9 | <div id='sound-and-music'> <div class='checkbox-div'> Sound <input id='sound-checkbox' type='checkbox' checked/> </div> <div class='checkbox-div'> Music <input id='music-checkbox' type='checkbox'/> </div> </div> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | var SnailBait = function () { ... this.soundCheckbox= document.getElementById('sound-checkbox'); this.musicCheckbox= document.getElementById('music-checkbox'); this.soundOn= this.soundCheckbox.checked; this.musicOn= this.musicCheckbox.checked; ... }; ... snailBait.soundCheckbox.onchange = function (e) { snailBait.soundOn = snailBait.soundCheckbox.checked; }; snailBait.musicCheckbox.onchange = function (e) { snailBait.musicOn = snailBait.musicCheckbox.checked; if (snailBait.musicOn) { snailBait.soundtrack.play(); } else { snailBait.soundtrack.pause(); } }; |
1 2 3 4 5 6 7 8 9 10 11 | SnailBait.prototype = { SnailBait.prototype = { ... startGame: function () { if (this.musicOn) { this.soundtrack.play(); } requestNextAnimationFrame(this.animate); }, ... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | SnailBait.prototype = { ... togglePaused: function () { ... if (this.paused && this.musicOn) { this.soundtrack.pause(); } else if ( ! this.paused && this.musicOn) { this.soundtrack.play(); } }, }; |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |