mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 23:20:59 +00:00
Add displaywidth/height parameters to PIXI.Tilemap c'tor and save them.
Clean up _initWebGL to remove unused GL buffers. Clean up _renderBatch to remove unused srcWide/srcHigh variables. Set new Tile Shader's clipping uniform using displayWidth/Height.
This commit is contained in:
parent
5f55fb095e
commit
008de253ce
1 changed files with 12 additions and 12 deletions
|
@ -17,10 +17,16 @@
|
|||
* @param {integer} tileheight - The height of a single tile.
|
||||
* @param {Array} layer - Tilemap layer data from the map, arranged in mapheight lists of mapwidth Phaser.Tile objects (2d array).
|
||||
*/
|
||||
PIXI.Tilemap = function (texture, mapwidth, mapheight, tilewidth, tileheight, layer) {
|
||||
PIXI.Tilemap = function (texture, displaywidth, displayheight, mapwidth, mapheight, tilewidth, tileheight, layer) {
|
||||
|
||||
PIXI.DisplayObjectContainer.call(this);
|
||||
|
||||
/**
|
||||
* the clipping limits for this layer
|
||||
*/
|
||||
this.displayWidth = displaywidth;
|
||||
this.displayHeight = displayheight;
|
||||
|
||||
/**
|
||||
* The texture of the Tilemap
|
||||
*
|
||||
|
@ -106,7 +112,7 @@ PIXI.Tilemap.prototype._renderWebGL = function (renderSession) {
|
|||
// stop current render session batch drawing
|
||||
renderSession.spriteBatch.stop();
|
||||
|
||||
if (!this._vertexBuffer)
|
||||
if (!this.positionBuffer)
|
||||
{
|
||||
this._initWebGL(renderSession);
|
||||
}
|
||||
|
@ -124,11 +130,6 @@ PIXI.Tilemap.prototype._initWebGL = function (renderSession) {
|
|||
|
||||
var gl = renderSession.gl;
|
||||
|
||||
this._vertexBuffer = gl.createBuffer();
|
||||
this._indexBuffer = gl.createBuffer();
|
||||
this._uvBuffer = gl.createBuffer();
|
||||
this._colorBuffer = gl.createBuffer();
|
||||
|
||||
// create a GL buffer to transfer all the vertex position data through
|
||||
this.positionBuffer = gl.createBuffer();
|
||||
|
||||
|
@ -155,10 +156,6 @@ PIXI.Tilemap.prototype._renderBatch = function (renderSession) {
|
|||
var iTextureWide = 1.0 / this.texture.width;
|
||||
var iTextureHigh = 1.0 / this.texture.height;
|
||||
|
||||
// size of one tile in the source texture
|
||||
var srcWide = this.tileWide * iTextureWide;
|
||||
var srcHigh = this.tileHigh * iTextureHigh;
|
||||
|
||||
// pre-calculate inverse half-buffer dimensions
|
||||
var iWide = 1.0 / screenWide2;
|
||||
var iHigh = 1.0 / screenHigh2;
|
||||
|
@ -175,6 +172,7 @@ PIXI.Tilemap.prototype._renderBatch = function (renderSession) {
|
|||
|
||||
for (var i = 0, l = this.glBatch.length; i < l; i++)
|
||||
{
|
||||
// each object in this.glBatch has properties:
|
||||
// sx: this.drawCoords[coordIndex],
|
||||
// sy: this.drawCoords[coordIndex + 1],
|
||||
// sw: this.tileWidth,
|
||||
|
@ -183,7 +181,6 @@ PIXI.Tilemap.prototype._renderBatch = function (renderSession) {
|
|||
// dy: y,
|
||||
// dw: this.tileWidth,
|
||||
// dh: this.tileHeight
|
||||
|
||||
var t = this.glBatch[i];
|
||||
|
||||
if (!t)
|
||||
|
@ -286,6 +283,9 @@ PIXI.Tilemap.prototype._renderWholeTilemap = function (renderSession) {
|
|||
// set the global offset (e.g. screen shake)
|
||||
gl.uniform2f(shader.uOffset, renderSession.offset.x / this.game.width * 2, -renderSession.offset.y / this.game.height * 2);
|
||||
|
||||
// set the clippling limits
|
||||
gl.uniform2f(shader.uClipping, this.displayWidth, this.game.height - this.displayHeight);
|
||||
|
||||
// set the offset in screen units to the center of the screen
|
||||
// and flip the GL y coordinate to be zero at the top
|
||||
gl.uniform2f(shader.uCentreOffset, 1, -1);
|
||||
|
|
Loading…
Reference in a new issue