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 playing = true; | |
//call this function to start the loop | |
function startRaf(){ | |
rafGo(); | |
} | |
function rafGo() { | |
//loop stops when playing is set to false | |
if(playing){ |
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
<!-- Insert this script after processing.js is included --> | |
<script type="text/javascript"> | |
var bound = false; | |
var pjs; | |
function bindJavascript() { | |
//reference the ID of your canvas that will be rendering your processing sketch | |
pjs = Processing.getInstanceById('polybranch'); | |
if(pjs!=null) { | |
pjs.bindJavascript(this); |
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
//at the top of your .pde or .pjs | |
void bindJavascript(JavaScript js) { | |
javascript = js; | |
} | |
JavaScript javascript; |
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
if((navigator.userAgent.match(/iPad/i)) || window.innerWidth >= 640){ | |
resolution = 4; | |
diglettSprite.src = "img/spritesx4.png"; | |
document.getElementsByTagName('html')[0].className += " hd"; | |
hd = true; | |
}else{ | |
resolution = 3; | |
diglettSprite.src = "img/spritesx3.png"; | |
} |
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
polygon:hover{ | |
cursor: pointer; | |
stroke: #ff0000; | |
stroke-width: 2px; | |
} |
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 _has_touch = ('ontouchstart' in window); | |
//determine which event we're listening for based on touch availability | |
var touchEvent = (_has_touch) ? "touchstart" : "mousedown"; | |
//bind our event listener to our event variable | |
document.getElementById('gameWrapper').addEventListener(touchEvent,function(e){ | |
var touchPosX = (e.type == "mousedown") ? e.layerX : e.touches[0].pageX; | |
var touchPosY = (e.type == "mousedown") ? e.layerY : e.touches[0].pageY; | |
//We have extracted the coordinates from the input event! Deal with them here. |
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
Diglett.prototype.setX = function(){ | |
this.x = randomXToY(0, parseInt(canvas.getAttribute('width')) - this.width); | |
if(this.x % resolution > 0){ | |
this.x -= this.x % resolution; | |
} | |
} |
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
//set up canvas and sprites | |
if(window.innerWidth >= 640){ | |
resolution = 4; | |
diglettSprite.src = "img/spritesx4.png"; | |
document.getElementsByTagName('html')[0].className += " hd"; | |
hd = true; | |
}else{ | |
diglettSprite.src = "img/spritesx3.png"; | |
} |