Skip to content

Commit c3eb8bf

Browse files
committed
StaticTilemap position + scrollFactor
1 parent b7fd964 commit c3eb8bf

4 files changed

Lines changed: 12 additions & 2 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '0ead5460-4cc8-11e7-b402-85a6b30f7408'
2+
build: 'b0c28c60-4d28-11e7-bd40-53a521c25ff2'
33
};
44
module.exports = CHECKSUM;

v3/src/gameobjects/tilemap/static/StaticTilemap.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ var StaticTilemap = new Class({
4242
this.mapHeight = mapHeight;
4343
this.dirty = true;
4444
this.vertexCount = 0;
45+
this.scrollFactorX = 1.0;
46+
this.scrollFactorY = 1.0;
4547
this.setTexture(texture, frame);
4648
this.setPosition(x, y);
4749
this.setSizeToFrame();
@@ -145,6 +147,8 @@ var StaticTilemap = new Class({
145147
this.dirty = false;
146148
}
147149
this.tilemapRenderer.shader.setConstantFloat2(this.tilemapRenderer.scrollLocation, -scrollX, -scrollY);
150+
this.tilemapRenderer.shader.setConstantFloat2(this.tilemapRenderer.scrollFactorLocation, this.scrollFactorX, this.scrollFactorY);
151+
this.tilemapRenderer.shader.setConstantFloat2(this.tilemapRenderer.tilemapPositionLocation, this.x, this.y);
148152
}
149153
}
150154

v3/src/renderer/webgl/renderers/tilemaprenderer/TilemapRenderer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ TilemapRenderer.prototype = {
4848
var shader = this.manager.resourceManager.createShader('TilemapShader', TilemapShader);
4949
var viewMatrixLocation = shader.getUniformLocation('u_view_matrix');
5050
var scrollLocation = shader.getUniformLocation('u_scroll');
51+
var scrollFactorLocation = shader.getUniformLocation('u_scroll_factor');
52+
var tilemapPositionLocation = shader.getUniformLocation('u_tilemap_position');
5153

5254
this.shader = shader;
5355
this.viewMatrixLocation = viewMatrixLocation;
5456
this.scrollLocation = scrollLocation;
57+
this.scrollFactorLocation = scrollFactorLocation;
58+
this.tilemapPositionLocation = tilemapPositionLocation;
5559

5660
this.resize(this.width, this.height, this.game.config.resolution);
5761
},

v3/src/renderer/webgl/shaders/TilemapShader.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ module.exports = {
22
vert: [
33
'uniform mat4 u_view_matrix;',
44
'uniform vec2 u_scroll;',
5+
'uniform vec2 u_scroll_factor;',
6+
'uniform vec2 u_tilemap_position;',
57
'attribute vec2 a_position;',
68
'attribute vec2 a_tex_coord;',
79
'varying vec2 v_tex_coord;',
810
'void main () {',
9-
' gl_Position = u_view_matrix * vec4(a_position + u_scroll, 1.0, 1.0);',
11+
' gl_Position = u_view_matrix * vec4(u_tilemap_position + a_position + (u_scroll * u_scroll_factor), 1.0, 1.0);',
1012
' v_tex_coord = a_tex_coord;',
1113
'}'
1214
].join('\n'),

0 commit comments

Comments
 (0)