Skip to content
This repository
Browse code

Stage options and multiResolution flag is added

  • Loading branch information...
commit c23d1b8bf27d2052239e6b9f88dfb38b920d91d4 1 parent 0934359
Denis Radin authored

Showing 2 changed files with 30 additions and 24 deletions. Show diff stats Hide diff stats

  1. +3 3 examples/yazz/index.html
  2. +27 21 src/display-canvas/Stage.js
6 examples/yazz/index.html
@@ -21,10 +21,10 @@
21 21 <canvas id="yazzStage"></canvas>
22 22 </body>
23 23 <script>
24   - var stage = new Stage('#yazzStage');
  24 + var stage = new Stage('#yazzStage', 800, 600, {multiResolution: false});
25 25
26   - //This is absolutely bad practice to load Assets throught DisplayObject constructor. Please, use AssetsList instead. Look at Scaling assets example.
27   - var testObject = new DisplayObject('http://www.rybaki.kz/cdata/jaz_/43.jpg');
  26 + //This is absolutely bad practice to load Assets throught DisplayObject constructor. Please, use AssetsList instead. Look at ScalingAssets example.
  27 + var testObject = new DisplayObject('../../assets/yazz.jpg');
28 28
29 29 testObject.x = 100;
30 30 testObject.y = 100;
48 src/display-canvas/Stage.js
@@ -7,8 +7,8 @@
7 7 */
8 8
9 9 (function(w) {
10   - var Stage = function(selector, baseWidth, baseHeight) {
11   - this.enabled = true;
  10 + var Stage = function(selector, baseWidth, baseHeight, options) {
  11 + this.options = options || {};
12 12
13 13 this.canvas = typeof selector == 'string' ? document.querySelector(selector) : selector;
14 14
@@ -20,27 +20,32 @@
20 20
21 21 //TODO delete after TextField and onClick/HitTest would be implemented
22 22 if (this.canvas.leftOffset) this.leftOffset = this.canvas.leftOffset;
23   -
24   - this.baseWidth = baseWidth || 480;
25   - this.baseHeight = baseHeight || 320;
26 23
27   - this.resize();
28   -
29   - var canvasWidth = this.canvas.offsetWidth || parseInt(this.canvas.style.width);
30   - var canvasHeight = this.canvas.offsetHeight || parseInt(this.canvas.style.height);
31   -
32   - var windowWidth = window.parent ? window.parent.innerWidth : window.innerWidth;
33   - var widnowHeight = window.parent ? window.parent.innerHeight :window.innerHeight;
  24 + this.baseWidth = baseWidth || 480;
  25 + this.baseHeight = baseHeight || 320;
  26 +
  27 + if (this.options.multiResolution === true || this.options.multiResolution === undefined){
  28 + this.resize();
  29 +
  30 + var canvasWidth = this.canvas.offsetWidth || parseInt(this.canvas.style.width);
  31 + var canvasHeight = this.canvas.offsetHeight || parseInt(this.canvas.style.height);
34 32
35   - this.scale = Math.min(canvasWidth / this.baseWidth, canvasHeight / this.baseHeight);
36   - this.pixelScale = Math.min(windowWidth / this.baseWidth, widnowHeight / this.baseHeight);
37   - this.pixelScale = Math.max(1, Math.ceil(this.pixelScale));
38   - this.pixelScale = Math.min(4, this.pixelScale);
  33 + var windowWidth = window.parent ? window.parent.innerWidth : window.innerWidth;
  34 + var widnowHeight = window.parent ? window.parent.innerHeight :window.innerHeight;
39 35
40   - this.width = this.canvas.width = this.baseWidth * this.pixelScale;
41   - this.height = this.canvas.height = this.baseHeight * this.pixelScale;
  36 + this.scale = Math.min(canvasWidth / this.baseWidth, canvasHeight / this.baseHeight);
42 37
43   - this.canvas.pixelScale = this.pixelScale;
  38 + this.pixelScale = Math.min(windowWidth / this.baseWidth, widnowHeight / this.baseHeight);
  39 + this.pixelScale = Math.max(1, Math.ceil(this.pixelScale));
  40 + this.pixelScale = Math.min(4, this.pixelScale);
  41 +
  42 + this.canvas.pixelScale = this.pixelScale;
  43 + } else {
  44 + this.canvas.pixelScale = this.pixelScale = 1;
  45 + }
  46 +
  47 + this.width = this.canvas.width = this.baseWidth * this.pixelScale;
  48 + this.height = this.canvas.height = this.baseHeight * this.pixelScale;
44 49
45 50 this.lastFrameTime = Date.now();
46 51
@@ -93,6 +98,7 @@
93 98 w.flash.initTouch(this);
94 99
95 100 this.childs = [];
  101 + this.enabled = true;
96 102 }
97 103
98 104 var p = Stage.prototype = new DisplayList();
@@ -134,7 +140,7 @@
134 140 var optimalRatio = Math.min(scaleToFitX, scaleToFitY);
135 141 this.scale = this.canvas.scale = optimalRatio;
136 142
137   - //if (this.scaleToScreen === true){
  143 + if (this.scaleToScreen === true){
138 144 if (currentScreenRatio >= 1.77 && currentScreenRatio <= 1.79) {
139 145 this.canvas.style.width = containerWidth + "px";
140 146 this.canvas.style.height = containerHeight + "px";
@@ -143,7 +149,7 @@
143 149 this.canvas.style.width = this.baseWidth * optimalRatio + "px";
144 150 this.canvas.style.height = this.baseHeight * optimalRatio + "px";
145 151 }
146   - //}
  152 + }
147 153
148 154 var leftOffset = (window.innerWidth - this.baseWidth * optimalRatio) / 2;
149 155 this.leftOffset = this.canvas.leftOffset = leftOffset;

0 comments on commit c23d1b8

Please sign in to comment.
Something went wrong with that request. Please try again.