This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var img = new Image(); | |
| setup = function() { | |
| var body = document.getElementById('body'); | |
| var canvas = document.createElement('canvas'); | |
| var ctx = canvas.getContext('2d'); | |
| canvas.width = window.innerWidth; | |
| canvas.height = window.innerHeight; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| setup = function() { | |
| var body = document.getElementById("body"); | |
| var canvas = document.createElement("canvas"); | |
| canvas.width = 1200; | |
| canvas.height = 720; | |
| body.appendChild(canvas); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Weapon = Class.extend({ | |
| init: function() { | |
| } | |
| }); | |
| MachineGun = Weapon.extend({ | |
| init: function() { | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var myObject = function(name){ | |
| this.name = name; | |
| return this; | |
| }; | |
| console.log(typeof myObject.prototype); // object | |
| myObject.prototype.getName = function(){ | |
| return this.name; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var manipulateDOM = function() { | |
| var body=document.getElementById("body"); | |
| var div=document.createElement("div"); | |
| if(div){ | |
| div.id = "gameContent"; | |
| var canvas=document.createElement("canvas"); | |
| canvas.id = "gameCanvas"; | |
| try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Error | |
| functionOne(); | |
| var functionOne = function() { | |
| // | |
| } | |
| // No error | |
| functionTwo(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function xhrGet(reqUri, callback, type) { | |
| var caller = xhrGet.caller; | |
| var xhr = new XMLHttpRequest(); | |
| xhr.open("GET", reqUri, true); | |
| if (type) xhr.responseType = type; | |
| xhr.onload=function () { | |
| if (callback) { | |
| try { | |
| callback(xhr); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var setup = function() { | |
| var soundRequest = new XMLHttpRequest(); | |
| soundRequest.open("GET", "/media/audio/gamedev/bg_menu.ogg", true); | |
| soundRequest.responseType = "arraybuffer"; | |
| soundRequest.onload = function () { | |
| try { | |
| // | |
| } | |
| catch(e) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| parseJSON = function (weaponJSON) { | |
| var parsedJSON = JSON.parse(weaponJSON); | |
| return parsedJSON['frames']['chaingun_impact.png']['spriteSourceSize']['x']; | |
| }; | |
| var setup = function() { | |
| var xmlRequest = new XMLHttpRequest(); | |
| xmlRequest.open("GET", "/media/resources/gamedev/weapon.json", true); | |
| xmlRequest.onload = function () { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| JSONExample = { | |
| "frames": { | |
| "chaingun_impact.png": { | |
| "frame": { | |
| "x":1162, | |
| "y":322, | |
| "w":38, | |
| "h":34}, | |
| "rotated": false, | |
| "trimmed": true, |