Comparing version 1.0.0 to 1.1.0
39
index.js
@@ -67,2 +67,7 @@ var getGL = require('webgl-context'); | ||
//FPS counter | ||
this.fps = 60; | ||
this._frames = 0; | ||
this._prevTime = this._then; | ||
if (!this._ignoreResize) { | ||
@@ -79,3 +84,3 @@ window.addEventListener("resize", function() { | ||
if (typeof render === "function") { | ||
this.onRender = render; | ||
this.onRender = render.bind(this); | ||
} else { | ||
@@ -90,2 +95,10 @@ //dummy render function | ||
this._frames++; | ||
if (now > this._prevTime + 1000) { | ||
this.fps = Math.round((this._frames * 1000) / (now - this._prevTime)); | ||
this._prevTime = now; | ||
this._frames = 0; | ||
} | ||
if (!this.isWebGL) { | ||
@@ -120,2 +133,22 @@ this.context.save(); | ||
Object.defineProperty(CanvasApp.prototype, 'retinaEnabled', { | ||
set: function(v) { | ||
this._retina = v; | ||
this._DPR = this._retina ? (window.devicePixelRatio||1) : 1; | ||
this.resize(this.width, this.height); | ||
}, | ||
get: function() { | ||
return this._retina; | ||
} | ||
}); | ||
CanvasApp.prototype.resetFPS = function() { | ||
this._frames = 0; | ||
this._prevTime = Date.now(); | ||
this._then = this._prevTime; | ||
this.fps = 60; | ||
}; | ||
CanvasApp.prototype.start = function() { | ||
@@ -128,4 +161,6 @@ if (this.running) | ||
//reset FPS counter | ||
this.resetFPS(); | ||
this.running = true; | ||
this._then = Date.now(); | ||
this._lastFrame = requestAnimationFrame(this._renderHandler); | ||
@@ -132,0 +167,0 @@ }; |
{ | ||
"name": "canvas-app", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "sets up a retina-scaled canvas with render loop", | ||
@@ -12,2 +12,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"domready": "^1.0.5", | ||
"tape": "~2.13.2" | ||
@@ -14,0 +15,0 @@ }, |
@@ -12,2 +12,3 @@ # canvas-app | ||
- start/stop handling | ||
- current FPS | ||
@@ -20,3 +21,5 @@ Simplest use might look like this: | ||
context.clearRect(0, 0, width, height); | ||
context.fillRect(0, 0, 25, 25); | ||
context.fillRect(20, 50, 25, 25); | ||
context.fillText("FPS: "+this.fps, 20, 20); | ||
} | ||
@@ -23,0 +26,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10865
6
158
91
2