Skip to content

Instantly share code, notes, and snippets.

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){
<!-- 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);
//at the top of your .pde or .pjs
void bindJavascript(JavaScript js) {
javascript = js;
}
JavaScript javascript;
@gbatha
gbatha / resolution.js
Created November 16, 2012 03:25
resolution variable
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";
}
@gbatha
gbatha / svghover.css
Created November 15, 2012 02:19
SVG polygon hover
polygon:hover{
cursor: pointer;
stroke: #ff0000;
stroke-width: 2px;
}
@gbatha
gbatha / touchevents.js
Created October 24, 2012 08:05
Touch events with mouse events fallback
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.
@gbatha
gbatha / round-to-pixel.js
Created October 24, 2012 07:25
Round to the nearest "whole pixel" based on resolution
Diglett.prototype.setX = function(){
this.x = randomXToY(0, parseInt(canvas.getAttribute('width')) - this.width);
if(this.x % resolution > 0){
this.x -= this.x % resolution;
}
}
//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";
}