Skip to content

Commit

Permalink
fixed device scaling with cocoonjs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zolmeister committed Feb 16, 2014
1 parent 3e2ac6d commit 9083e5f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
8 changes: 4 additions & 4 deletions bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ var initializeOnUp = false

window.onresize = resizeWindow
function resizeWindow() {
$canv.width = window.innerWidth * devicePixelRatio * quality / 10
$canv.height = window.innerHeight * devicePixelRatio * quality / 10
$canv.width = window.innerWidth * devPixelRatio * quality / 10
$canv.height = window.innerHeight * devPixelRatio * quality / 10
ctx = $canv.getContext('2d')
ctx.lineJoin = 'round'

Expand All @@ -33,12 +33,12 @@ function resizeWindow() {

function eventPos(e) {
if (e.type.indexOf('touch') === -1){ // if its a mouse coord
return {x: e.pageX*window.devicePixelRatio, y: e.pageY*window.devicePixelRatio, width: 1, height: 1}
return {x: e.pageX*devPixelRatio, y: e.pageY*devPixelRatio, width: 1, height: 1}
}

// touch event coord
if(e.type === 'touchend') return {x: 0, y: 0, width: 0, height: 0}
return {x: e.touches[0].pageX*window.devicePixelRatio - 35, y: e.touches[0].pageY*window.devicePixelRatio - 35, width: 70, height: 70}
return {x: e.touches[0].pageX*devPixelRatio - 35, y: e.touches[0].pageY*devPixelRatio - 35, width: 70, height: 70}
}

$canv.addEventListener('mousedown', touchDown)
Expand Down
2 changes: 1 addition & 1 deletion cache.appcache
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CACHE MANIFEST
#build 1.1.1
#build 1.1.1.1

CACHE:
#NETWORK:
Expand Down
13 changes: 7 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"use strict";

function setGlobals() {

window.devicePixelRatio = (window.devicePixelRatio > 2 ? 2 : window.devicePixelRatio) || 1
// window.ext is set by cocoonjs
window.isMobile = !!window.ext

window.devPixelRatio = (window.devicePixelRatio > 2 ? 2 : window.devicePixelRatio) || 1
window.$canv = document.getElementById('mainCanv')
$canv.width = window.innerWidth * devicePixelRatio
$canv.height = window.innerHeight * devicePixelRatio
$canv.width = window.innerWidth * devPixelRatio
$canv.height = window.innerHeight * devPixelRatio
window.ctx = $canv.getContext('2d')

ctx.lineJoin = 'round'
Expand All @@ -14,8 +16,7 @@ function setGlobals() {
// this probably shouldnt be a global...
window.usingSmallLogo = false

// window.ext is set by cocoonjs
window.isMobile = !!window.ext

// color pallet // blue l blue l green orange d orange
window.pallet = [[105,210,231], [167,219,216], [224,228,204], [243,134,48], [250,105,0]]
window.lastColor = new Color()
Expand Down

0 comments on commit 9083e5f

Please sign in to comment.