Skip to content

Commit c3c3532

Browse files
authored
Merge pull request phaserjs#4992 from svipal/master
Preliminary PR for isometric support
2 parents 6bc858e + 7992070 commit c3c3532

37 files changed

Lines changed: 1703 additions & 286 deletions

src/const.js

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,69 @@ var CONST = {
131131
* @type {integer}
132132
* @since 3.0.0
133133
*/
134-
RIGHT: 8
134+
RIGHT: 8,
135+
136+
137+
/**
138+
* Orientation constant.
139+
*
140+
* @name Phaser.ORTHOGONAL
141+
* @const
142+
* @type {integer}
143+
* @since 3.2.2
144+
*/
145+
ORTHOGONAL: 0,
146+
147+
148+
/**
149+
* Orientation constant.
150+
*
151+
* @name Phaser.ISOMETRIC
152+
* @const
153+
* @type {integer}
154+
* @since 3.2.2
155+
*/
156+
ISOMETRIC: 1,
157+
158+
159+
/**
160+
* Orientation constant.
161+
*
162+
* @name Phaser.STAGGERED
163+
* @const
164+
* @type {integer}
165+
* @since 3.2.2
166+
*/
167+
STAGGERED: 2,
168+
169+
/**
170+
* Orientation constant.
171+
*
172+
* @name Phaser.HEXAGONAL
173+
* @const
174+
* @type {integer}
175+
* @since 3.2.2
176+
*/
177+
HEXAGONAL: 3,
178+
179+
fromOrientationString: function (orientation)
180+
{
181+
var constor = CONST.ORTHOGONAL;
182+
183+
if (orientation === 'isometric')
184+
{
185+
constor = CONST.ISOMETRIC;
186+
}
187+
else if (orientation === 'staggered')
188+
{
189+
constor = CONST.STAGGERED;
190+
}
191+
else if (orientation === 'hexagonal')
192+
{
193+
constor = CONST.HEXAGONAL;
194+
}
195+
return constor;
196+
}
135197

136198
};
137199

src/physics/arcade/World.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,8 +2254,10 @@ var World = new Class({
22542254

22552255
tilemapLayer = tile.tilemapLayer;
22562256

2257-
tileWorldRect.left = tilemapLayer.tileToWorldX(tile.x);
2258-
tileWorldRect.top = tilemapLayer.tileToWorldY(tile.y);
2257+
var point = tilemapLayer.tileToWorldXY(tile.x,tile.y);
2258+
2259+
tileWorldRect.left = point.x;
2260+
tileWorldRect.top = point.y;
22592261

22602262
// If the map's base tile size differs from the layer's tile size, only the top of the rect
22612263
// needs to be adjusted since its origin is (0, 1).
Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
#define SHADER_NAME PHASER_MULTI_FS
2-
3-
precision mediump float;
4-
5-
uniform sampler2D uMainSampler[%count%];
6-
7-
varying vec2 outTexCoord;
8-
varying float outTexId;
9-
varying float outTintEffect;
10-
varying vec4 outTint;
11-
12-
void main()
13-
{
14-
vec4 texture;
15-
16-
%forloop%
17-
18-
vec4 texel = vec4(outTint.bgr * outTint.a, outTint.a);
19-
20-
// Multiply texture tint
21-
vec4 color = texture * texel;
22-
23-
if (outTintEffect == 1.0)
24-
{
25-
// Solid color + texture alpha
26-
color.rgb = mix(texture.rgb, outTint.bgr * outTint.a, texture.a);
27-
}
28-
29-
gl_FragColor = color;
30-
}
1+
#define SHADER_NAME PHASER_MULTI_FS
2+
3+
precision mediump float;
4+
5+
uniform sampler2D uMainSampler[%count%];
6+
7+
varying vec2 outTexCoord;
8+
varying float outTexId;
9+
varying float outTintEffect;
10+
varying vec4 outTint;
11+
12+
void main()
13+
{
14+
vec4 texture;
15+
16+
%forloop%
17+
18+
vec4 texel = vec4(outTint.bgr * outTint.a, outTint.a);
19+
20+
// Multiply texture tint
21+
vec4 color = texture * texel;
22+
23+
if (outTintEffect == 1.0)
24+
{
25+
// Solid color + texture alpha
26+
color.rgb = mix(texture.rgb, outTint.bgr * outTint.a, texture.a);
27+
}
28+
29+
gl_FragColor = color;
30+
}
Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
#define SHADER_NAME PHASER_MULTI_VS
2-
3-
precision mediump float;
4-
5-
uniform mat4 uProjectionMatrix;
6-
uniform mat4 uViewMatrix;
7-
uniform mat4 uModelMatrix;
8-
9-
attribute vec2 inPosition;
10-
attribute vec2 inTexCoord;
11-
attribute float inTexId;
12-
attribute float inTintEffect;
13-
attribute vec4 inTint;
14-
15-
varying vec2 outTexCoord;
16-
varying float outTexId;
17-
varying float outTintEffect;
18-
varying vec4 outTint;
19-
20-
void main ()
21-
{
22-
gl_Position = uProjectionMatrix * uViewMatrix * uModelMatrix * vec4(inPosition, 1.0, 1.0);
23-
24-
outTexCoord = inTexCoord;
25-
outTexId = inTexId;
26-
outTint = inTint;
27-
outTintEffect = inTintEffect;
28-
}
29-
1+
#define SHADER_NAME PHASER_MULTI_VS
2+
3+
precision mediump float;
4+
5+
uniform mat4 uProjectionMatrix;
6+
uniform mat4 uViewMatrix;
7+
uniform mat4 uModelMatrix;
8+
9+
attribute vec2 inPosition;
10+
attribute vec2 inTexCoord;
11+
attribute float inTexId;
12+
attribute float inTintEffect;
13+
attribute vec4 inTint;
14+
15+
varying vec2 outTexCoord;
16+
varying float outTexId;
17+
varying float outTintEffect;
18+
varying vec4 outTint;
19+
20+
void main ()
21+
{
22+
gl_Position = uProjectionMatrix * uViewMatrix * uModelMatrix * vec4(inPosition, 1.0, 1.0);
23+
24+
outTexCoord = inTexCoord;
25+
outTexId = inTexId;
26+
outTint = inTint;
27+
outTintEffect = inTintEffect;
28+
}
29+
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
#define SHADER_NAME PHASER_SINGLE_FS
2-
3-
precision mediump float;
4-
5-
uniform sampler2D uMainSampler;
6-
7-
varying vec2 outTexCoord;
8-
varying float outTintEffect;
9-
varying vec4 outTint;
10-
11-
void main()
12-
{
13-
vec4 texture = texture2D(uMainSampler, outTexCoord);
14-
vec4 texel = vec4(outTint.bgr * outTint.a, outTint.a);
15-
16-
// Multiply texture tint
17-
vec4 color = texture * texel;
18-
19-
if (outTintEffect == 1.0)
20-
{
21-
// Solid color + texture alpha
22-
color.rgb = mix(texture.rgb, outTint.bgr * outTint.a, texture.a);
23-
}
24-
25-
gl_FragColor = color;
26-
}
1+
#define SHADER_NAME PHASER_SINGLE_FS
2+
3+
precision mediump float;
4+
5+
uniform sampler2D uMainSampler;
6+
7+
varying vec2 outTexCoord;
8+
varying float outTintEffect;
9+
varying vec4 outTint;
10+
11+
void main()
12+
{
13+
vec4 texture = texture2D(uMainSampler, outTexCoord);
14+
vec4 texel = vec4(outTint.bgr * outTint.a, outTint.a);
15+
16+
// Multiply texture tint
17+
vec4 color = texture * texel;
18+
19+
if (outTintEffect == 1.0)
20+
{
21+
// Solid color + texture alpha
22+
color.rgb = mix(texture.rgb, outTint.bgr * outTint.a, texture.a);
23+
}
24+
25+
gl_FragColor = color;
26+
}
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
#define SHADER_NAME PHASER_SINGLE_VS
2-
3-
precision mediump float;
4-
5-
uniform mat4 uProjectionMatrix;
6-
uniform mat4 uViewMatrix;
7-
uniform mat4 uModelMatrix;
8-
9-
attribute vec2 inPosition;
10-
attribute vec2 inTexCoord;
11-
attribute float inTintEffect;
12-
attribute vec4 inTint;
13-
14-
varying vec2 outTexCoord;
15-
varying float outTintEffect;
16-
varying vec4 outTint;
17-
18-
void main ()
19-
{
20-
gl_Position = uProjectionMatrix * uViewMatrix * uModelMatrix * vec4(inPosition, 1.0, 1.0);
21-
22-
outTexCoord = inTexCoord;
23-
outTint = inTint;
24-
outTintEffect = inTintEffect;
25-
}
1+
#define SHADER_NAME PHASER_SINGLE_VS
2+
3+
precision mediump float;
4+
5+
uniform mat4 uProjectionMatrix;
6+
uniform mat4 uViewMatrix;
7+
uniform mat4 uModelMatrix;
8+
9+
attribute vec2 inPosition;
10+
attribute vec2 inTexCoord;
11+
attribute float inTintEffect;
12+
attribute vec4 inTint;
13+
14+
varying vec2 outTexCoord;
15+
varying float outTintEffect;
16+
varying vec4 outTint;
17+
18+
void main ()
19+
{
20+
gl_Position = uProjectionMatrix * uViewMatrix * uModelMatrix * vec4(inPosition, 1.0, 1.0);
21+
22+
outTexCoord = inTexCoord;
23+
outTint = inTint;
24+
outTintEffect = inTintEffect;
25+
}

src/tilemaps/Tile.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* @license {@link https://opensource.org/licenses/MIT|MIT License}
55
*/
66

7+
var CONST = require('../const.js');
78
var Class = require('../utils/Class');
89
var Components = require('../gameobjects/components');
910
var Rectangle = require('../geom/rectangle');
@@ -706,14 +707,34 @@ var Tile = new Class({
706707
*/
707708
updatePixelXY: function ()
708709
{
709-
// Tiled places tiles on a grid of baseWidth x baseHeight. The origin for a tile is the
710-
// bottom left, while the Phaser renderer assumes the origin is the top left. The y
711-
// coordinate needs to be adjusted by the difference.
712-
this.pixelX = this.x * this.baseWidth;
713-
this.pixelY = this.y * this.baseHeight;
714-
715-
// this.pixelY = this.y * this.baseHeight - (this.height - this.baseHeight);
716-
710+
if (this.layer.orientation === CONST.ISOMETRIC)
711+
{
712+
// reminder : for the tilemap to be centered we have to move the image to the right with the camera !
713+
// this is crucial for wordtotile, tiletoworld to work.
714+
this.pixelX = (this.x - this.y) * this.baseWidth * 0.5;
715+
this.pixelY = (this.x + this.y) * this.baseHeight * 0.5;
716+
}
717+
else if (this.layer.orientation === CONST.STAGGERED)
718+
{
719+
this.pixelX = this.x * this.baseWidth + this.y % 2 * (this.baseWidth / 2);
720+
this.pixelY = this.y * (this.baseHeight / 2);
721+
}
722+
else if (this.layer.orientation === CONST.HEXAGONAL)
723+
{
724+
var sidel = this.layer.hexSideLength;
725+
var rowHeight = ((this.baseHeight - sidel) / 2 + sidel);
726+
this.pixelX = this.x * this.baseWidth + this.y % 2 * (this.baseWidth / 2);
727+
this.pixelY = this.y * rowHeight;
728+
}
729+
else if (this.layer.orientation === CONST.ORTHOGONAL)
730+
{
731+
// In orthogonal mode, Tiled places tiles on a grid of baseWidth x baseHeight. The origin for a tile is the
732+
// bottom left, while the Phaser renderer assumes the origin is the top left. The y
733+
// coordinate needs to be adjusted by the difference.
734+
this.pixelX = this.x * this.baseWidth;
735+
this.pixelY = this.y * this.baseHeight;
736+
737+
}
717738
return this;
718739
},
719740

0 commit comments

Comments
 (0)