diff --git a/v3/src/gameobjects/tilesprite/TileSprite.js b/v3/src/gameobjects/tilesprite/TileSprite.js index 437edabd9..e3ce466ee 100644 --- a/v3/src/gameobjects/tilesprite/TileSprite.js +++ b/v3/src/gameobjects/tilesprite/TileSprite.js @@ -3,6 +3,7 @@ var Class = require('../../utils/Class'); var GameObject = require('../GameObject'); var Components = require('../../components'); var TileSpriteRender = require('./TileSpriteRender'); +var CanvasPool = require('../../dom/CanvasPool') var TileSprite = new Class({ @@ -25,17 +26,29 @@ var TileSprite = new Class({ initialize: - function TileSprite (state, x, y, texture, frame) + function TileSprite (state, x, y, width, height, texture, frame) { + var resourceManager = state.game.renderer.resourceManager; + var gl; + GameObject.call(this, state, 'TileSprite'); this.tilePositionX = 0; this.tilePositionY = 0; + this.canvasBuffer = CanvasPool.create2D(null, width, height); + this.canvasBufferCtx = this.canvasBuffer.getContext('2d'); + this.dirty = false; this.setTexture(texture, frame); this.setPosition(x, y); this.setSizeToFrame(); this.setOrigin(); + + }, + + updateTileTexture: function () + { + } }); diff --git a/v3/src/gameobjects/tilesprite/TileSpriteFactory.js b/v3/src/gameobjects/tilesprite/TileSpriteFactory.js index fe0943e59..333ad2441 100644 --- a/v3/src/gameobjects/tilesprite/TileSpriteFactory.js +++ b/v3/src/gameobjects/tilesprite/TileSpriteFactory.js @@ -6,14 +6,14 @@ var TileSpriteFactory = { KEY: 'tileSprite', - add: function (x, y, key, frame) + add: function (x, y, width, height, key, frame) { - return this.children.add(new TileSprite(this.state, x, y, key, frame)); + return this.children.add(new TileSprite(this.state, x, y, width, height, key, frame)); }, - make: function (x, y, key, frame) + make: function (x, y, width, height, key, frame) { - return new TileSprite(this.state, x, y, key, frame); + return new TileSprite(this.state, x, y, width, height, key, frame); } }; diff --git a/v3/src/gameobjects/tilesprite/TileSpriteWebGLRenderer.js b/v3/src/gameobjects/tilesprite/TileSpriteWebGLRenderer.js index 87c5fcc02..df9e08a5a 100644 --- a/v3/src/gameobjects/tilesprite/TileSpriteWebGLRenderer.js +++ b/v3/src/gameobjects/tilesprite/TileSpriteWebGLRenderer.js @@ -4,6 +4,7 @@ var TileSpriteWebGLRenderer = function (renderer, src, interpolationPercentage, { return; } + renderer.tileBatch.addTileSprite(src, camera); }; module.exports = TileSpriteWebGLRenderer; diff --git a/v3/src/renderer/webgl/renderers/tilebatch/TileBatch.js b/v3/src/renderer/webgl/renderers/tilebatch/TileBatch.js index e93b0a9c9..fb051a42d 100644 --- a/v3/src/renderer/webgl/renderers/tilebatch/TileBatch.js +++ b/v3/src/renderer/webgl/renderers/tilebatch/TileBatch.js @@ -288,6 +288,8 @@ TileBatch.prototype = { var mva, mvb, mvc, mvd, mve, mvf, tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3; var sra, srb, src, srd, sre, srf, cma, cmb, cmc, cmd, cme, cmf; var alpha = gameObject.alpha; + var tilePositionX = gameObject.tilePositionX / width; + var tilePositionY = gameObject.tilePositionY / height; tempMatrix.applyITRS(translateX, translateY, rotation, scaleX, scaleY); @@ -327,29 +329,29 @@ TileBatch.prototype = { vertexBufferObjectF32[vertexOffset++] = tx0; vertexBufferObjectF32[vertexOffset++] = ty0; - vertexBufferObjectF32[vertexOffset++] = uvs.x0; - vertexBufferObjectF32[vertexOffset++] = uvs.y0; + vertexBufferObjectF32[vertexOffset++] = uvs.x0 + tilePositionX; + vertexBufferObjectF32[vertexOffset++] = uvs.y0 + tilePositionY; vertexBufferObjectU32[vertexOffset++] = 0xFFFFFF; //vertexColor.topLeft; vertexBufferObjectF32[vertexOffset++] = alpha; vertexBufferObjectF32[vertexOffset++] = tx1; vertexBufferObjectF32[vertexOffset++] = ty1; - vertexBufferObjectF32[vertexOffset++] = uvs.x1; - vertexBufferObjectF32[vertexOffset++] = uvs.y1; + vertexBufferObjectF32[vertexOffset++] = uvs.x1 + tilePositionX; + vertexBufferObjectF32[vertexOffset++] = uvs.y1 + tilePositionY; vertexBufferObjectU32[vertexOffset++] = 0xFFFFFF; //vertexColor.bottomLeft; vertexBufferObjectF32[vertexOffset++] = alpha; vertexBufferObjectF32[vertexOffset++] = tx2; vertexBufferObjectF32[vertexOffset++] = ty2; - vertexBufferObjectF32[vertexOffset++] = uvs.x2; - vertexBufferObjectF32[vertexOffset++] = uvs.y2; + vertexBufferObjectF32[vertexOffset++] = uvs.x2 + tilePositionX; + vertexBufferObjectF32[vertexOffset++] = uvs.y2 + tilePositionY; vertexBufferObjectU32[vertexOffset++] = 0xFFFFFF; //vertexColor.bottomRight; vertexBufferObjectF32[vertexOffset++] = alpha; vertexBufferObjectF32[vertexOffset++] = tx3; vertexBufferObjectF32[vertexOffset++] = ty3; - vertexBufferObjectF32[vertexOffset++] = uvs.x3; - vertexBufferObjectF32[vertexOffset++] = uvs.y3; + vertexBufferObjectF32[vertexOffset++] = uvs.x3 + tilePositionX; + vertexBufferObjectF32[vertexOffset++] = uvs.y3 + tilePositionY; vertexBufferObjectU32[vertexOffset++] = 0xFFFFFF; //vertexColor.topRight; vertexBufferObjectF32[vertexOffset++] = alpha; }