diff --git a/v3/src/boot/Game.js b/v3/src/boot/Game.js index 760c91bc0..62620370c 100644 --- a/v3/src/boot/Game.js +++ b/v3/src/boot/Game.js @@ -15,6 +15,7 @@ var StateManager = require('../state/StateManager'); var FactoryContainer = require('../gameobjects/FactoryContainer'); var GameObjects = require('../gameobjects/'); var TextureManager = require ('../textures/TextureManager'); +var AddToDOM = require('../dom/AddToDOM'); var Game = function (config) { @@ -98,6 +99,8 @@ Game.prototype = { CreateRenderer(this); + AddToDOM(this.canvas, this.config.parent); + this.state.boot(); this.isRunning = true; diff --git a/v3/src/checksum.js b/v3/src/checksum.js index 5424d18f7..a78139365 100644 --- a/v3/src/checksum.js +++ b/v3/src/checksum.js @@ -1,4 +1,4 @@ var CHECKSUM = { -build: '66ef5980-bc26-11e6-b62b-c7bd5e19f5c7' +build: '18d69660-bc2f-11e6-9837-952b15df5558' }; module.exports = CHECKSUM; \ No newline at end of file diff --git a/v3/src/gameobjects/image/ImageFactory.js b/v3/src/gameobjects/image/ImageFactory.js index a83ce4c05..29ca22052 100644 --- a/v3/src/gameobjects/image/ImageFactory.js +++ b/v3/src/gameobjects/image/ImageFactory.js @@ -34,7 +34,7 @@ var ImageFactory = { console.log('ImageFactory.add', key, x, y, frame, group); console.log('into State', this.state); - // return group.children.add(new Image(this.state, x, y, key, frame)); + return group.children.add(new Image(this.state, x, y, key, frame)); }, make: function (x, y, key, frame) diff --git a/v3/src/loader/filetypes/ImageFile.js b/v3/src/loader/filetypes/ImageFile.js index cb550403c..c658b2a33 100644 --- a/v3/src/loader/filetypes/ImageFile.js +++ b/v3/src/loader/filetypes/ImageFile.js @@ -32,11 +32,13 @@ ImageFile.prototype.onProcess = function (callback) this.data = new Image(); + this.data.crossOrigin = this.crossOrigin; + var _this = this; this.data.onload = function () { - window.URL.revokeObjectURL(_this.data.src); + URL.revokeObjectURL(_this.data.src); _this.onComplete(); @@ -45,14 +47,14 @@ ImageFile.prototype.onProcess = function (callback) this.data.onerror = function () { - window.URL.revokeObjectURL(_this.data.src); + URL.revokeObjectURL(_this.data.src); _this.state = CONST.FILE_ERRORED; callback(_this); }; - this.data.src = window.URL.createObjectURL(this.xhrLoader.response); + this.data.src = URL.createObjectURL(this.xhrLoader.response); }; module.exports = ImageFile; diff --git a/v3/src/renderer/webgl/WebGLRenderer.js b/v3/src/renderer/webgl/WebGLRenderer.js index 642217359..a6f4191f7 100644 --- a/v3/src/renderer/webgl/WebGLRenderer.js +++ b/v3/src/renderer/webgl/WebGLRenderer.js @@ -5,6 +5,7 @@ * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ +var CONST = require('../../const'); var CreateEmptyTexture = require('./utils/CreateEmptyTexture'); var QuadFBO = require('./utils/QuadFBO'); var BatchManager = require('./BatchManager'); @@ -24,7 +25,7 @@ var WebGLRenderer = function (game) */ this.game = game; - this.type = Phaser.WEBGL; + this.type = CONST.WEBGL; // Read all the following from game config this.clearBeforeRender = true; @@ -35,11 +36,11 @@ var WebGLRenderer = function (game) this.preserveDrawingBuffer = false; - this.width = game.width * game.resolution; + this.width = game.config.width * game.config.resolution; - this.height = game.height * game.resolution; + this.height = game.config.height * game.config.resolution; - this.resolution = game.resolution; + this.resolution = game.config.resolution; this.clipUnitX = 2 / this.width; @@ -148,10 +149,10 @@ WebGLRenderer.prototype = { gl.enable(gl.BLEND); // Transparent - gl.clearColor(0, 0, 0, 0); + // gl.clearColor(0, 0, 0, 0); // Black - // gl.clearColor(0, 0, 0, 1); + gl.clearColor(1, 0, 0, 1); this.shaderManager.init(); this.batch.init(); @@ -247,16 +248,18 @@ WebGLRenderer.prototype = { resize: function (width, height) { - this.width = width * this.game.resolution; - this.height = height * this.game.resolution; + var res = this.game.config.resolution; + + this.width = width * res; + this.height = height * res; this.view.width = this.width; this.view.height = this.height; if (this.autoResize) { - this.view.style.width = (this.width / this.game.resolution) + 'px'; - this.view.style.height = (this.height / this.game.resolution) + 'px'; + this.view.style.width = (this.width / res) + 'px'; + this.view.style.height = (this.height / res) + 'px'; } this.gl.viewport(0, 0, this.width, this.height); @@ -264,8 +267,8 @@ WebGLRenderer.prototype = { this.clipUnitX = 2 / this.width; this.clipUnitY = 2 / this.height; - this.projection.x = (this.width / 2) / this.game.resolution; - this.projection.y = -(this.height / 2) / this.game.resolution; + this.projection.x = (this.width / 2) / res; + this.projection.y = -(this.height / 2) / res; }, /** @@ -279,14 +282,14 @@ WebGLRenderer.prototype = { */ render: function (state, interpolationPercentage) { + // console.log('%c render start ', 'color: #ffffff; background: #00ff00;'); + // No point rendering if our context has been blown up! if (this.contextLost) { return; } - console.log('%c render start ', 'color: #ffffff; background: #00ff00;'); - // Add Pre-render hook this.startTime = Date.now(); @@ -300,7 +303,7 @@ WebGLRenderer.prototype = { // clear is needed for the FBO, otherwise corruption ... gl.clear(gl.COLOR_BUFFER_BIT); - this.setBlendMode(Phaser.blendModes.NORMAL); + this.setBlendMode(CONST.blendModes.NORMAL); this.drawCount = 0; @@ -413,16 +416,16 @@ WebGLRenderer.prototype = { // @see https://github.com/mrdoob/three.js/issues/9109 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source.image); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, source.scaleMode === Phaser.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, source.scaleMode === CONST.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); if (source.mipmap && source.isPowerOf2) { - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, source.scaleMode === Phaser.scaleModes.LINEAR ? gl.LINEAR_MIPMAP_LINEAR : gl.NEAREST_MIPMAP_NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, source.scaleMode === CONST.scaleModes.LINEAR ? gl.LINEAR_MIPMAP_LINEAR : gl.NEAREST_MIPMAP_NEAREST); gl.generateMipmap(gl.TEXTURE_2D); } else { - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, source.scaleMode === Phaser.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, source.scaleMode === CONST.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); } if (source.isPowerOf2) @@ -441,6 +444,7 @@ WebGLRenderer.prototype = { return true; }, + /* updateCompressedTexture: function (texture) { if (!texture.hasLoaded) @@ -497,6 +501,7 @@ WebGLRenderer.prototype = { return true; }, + */ // Blend Mode Manager diff --git a/v3/src/renderer/webgl/utils/QuadFBO.js b/v3/src/renderer/webgl/utils/QuadFBO.js index 81d78643b..c3111dfb1 100644 --- a/v3/src/renderer/webgl/utils/QuadFBO.js +++ b/v3/src/renderer/webgl/utils/QuadFBO.js @@ -4,6 +4,8 @@ * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ +var CreateEmptyTexture = require('./CreateEmptyTexture'); + /** * Frame Buffer Object with drawing quad + shader * @@ -100,7 +102,7 @@ QuadFBO.prototype = { gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0, 0, 1, 0, 0, 1, 1, 1 ]), gl.STATIC_DRAW); // Create a texture for our color buffer - this.texture = this.renderer.createEmptyTexture(width, height, 0, 0); + this.texture = CreateEmptyTexture(gl, width, height, 0, 0); // The FBO's depth buffer this.renderBuffer = gl.createRenderbuffer(); diff --git a/v3/src/state/StateManager.js b/v3/src/state/StateManager.js index 6e9218965..00ec3fc39 100644 --- a/v3/src/state/StateManager.js +++ b/v3/src/state/StateManager.js @@ -279,7 +279,7 @@ StateManager.prototype = { var width = newState.settings.width; var height = newState.settings.height; - // newState.sys.fbo = this.game.renderer.createFBO(newState, x, y, width, height); + newState.sys.fbo = this.game.renderer.createFBO(newState, x, y, width, height); }, getState: function (key) diff --git a/v3/src/state/systems/MainLoop.js b/v3/src/state/systems/MainLoop.js index 18b3ab0fe..c464a6394 100644 --- a/v3/src/state/systems/MainLoop.js +++ b/v3/src/state/systems/MainLoop.js @@ -192,7 +192,7 @@ MainLoop.prototype = { this.state.sys.updates.start(); - if (this.state.settings.visible && this.state.sys.color.alpha !== 0 && this.state.sys.children.list.length > 0) + if (this.state.settings.visible && this.state.sys.color.alpha !== 0) { this.game.renderer.render(this.state, this.frameDelta / this.timestep); }