Skip to content

Commit dd7ae12

Browse files
committed
ArcadePhysics.overlap and collide now recognise TileSprites in the collision checks.
1 parent a0961f2 commit dd7ae12

13 files changed

Lines changed: 250 additions & 42 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Updates:
7878
* Most of the GameObjectFactory functions now have a group parameter, so you can do: game.add.sprite(x, y, frame, frameName, group) rather than defaulting to the World group.
7979
* Group.countLiving and countDead used to return -1 if the Group was empty, but now return 0.
8080
* Text can now be fixedToCamera, updated world/fixed to camera example to show this.
81+
* ArcadePhysics.overlap and collide now recognise TileSprites in the collision checks.
8182

8283

8384
Bug Fixes:

examples/_site/examples.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@
216216
"file": "invaders.js",
217217
"title": "invaders"
218218
},
219+
{
220+
"file": "matching+pairs.js",
221+
"title": "matching pairs"
222+
},
219223
{
220224
"file": "starstruck.js",
221225
"title": "starstruck"
@@ -514,6 +518,22 @@
514518
"file": "angular+velocity.js",
515519
"title": "angular velocity"
516520
},
521+
{
522+
"file": "bounce+accelerator.js",
523+
"title": "bounce accelerator"
524+
},
525+
{
526+
"file": "bounce+knock.js",
527+
"title": "bounce knock"
528+
},
529+
{
530+
"file": "bounce+with+gravity.js",
531+
"title": "bounce with gravity"
532+
},
533+
{
534+
"file": "bounce.js",
535+
"title": "bounce"
536+
},
517537
{
518538
"file": "mass+velocity+test.js",
519539
"title": "mass velocity test"
@@ -538,6 +558,10 @@
538558
"file": "shoot+the+pointer.js",
539559
"title": "shoot the pointer"
540560
},
561+
{
562+
"file": "snake.js",
563+
"title": "snake"
564+
},
541565
{
542566
"file": "sprite+bounds.js",
543567
"title": "sprite bounds"
@@ -636,6 +660,10 @@
636660
"file": "animated+tiling+sprite.js",
637661
"title": "animated tiling sprite"
638662
},
663+
{
664+
"file": "colliding+with+tiling+sprite.js",
665+
"title": "colliding with tiling sprite"
666+
},
639667
{
640668
"file": "tiling+sprite.js",
641669
"title": "tiling sprite"

examples/assets/maps/tiles2.png

148 KB
Loading

examples/games/invaders.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ function create() {
3535
// The scrolling starfield background
3636
starfield = game.add.tileSprite(0, 0, 800, 600, 'starfield');
3737

38-
3938
// Our bullet group
4039
bullets = game.add.group();
4140
bullets.createMultiple(30, 'bullet');

examples/tile sprites/animated tiling sprite.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,44 @@ function preload() {
55
game.load.image('disk', 'assets/sprites/p2.jpeg');
66
}
77

8-
var s;
8+
var tilesprite;
9+
var cursors;
910
var count = 0;
1011

1112
function create() {
12-
s = game.add.tileSprite(0, 0, 512, 512, 'disk');
13+
14+
tilesprite = game.add.tileSprite(0, 0, 512, 512, 'disk');
15+
16+
cursors = game.input.keyboard.createCursorKeys();
17+
1318
}
1419

1520
function update() {
1621

1722
count += 0.005
1823

19-
s.tileScale.x = 2 + Math.sin(count);
20-
s.tileScale.y = 2 + Math.cos(count);
24+
tilesprite.tileScale.x = 2 + Math.sin(count);
25+
tilesprite.tileScale.y = 2 + Math.cos(count);
2126

22-
s.tilePosition.x += 1;
23-
s.tilePosition.y += 1;
27+
tilesprite.tilePosition.x += 1;
28+
tilesprite.tilePosition.y += 1;
2429

25-
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
30+
if (cursors.left.isDown)
2631
{
27-
s.x -= 4;
32+
tilesprite.x -= 4;
2833
}
29-
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
34+
else if (cursors.right.isDown)
3035
{
31-
s.x += 4;
36+
tilesprite.x += 4;
3237
}
3338

34-
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
39+
if (cursors.up.isDown)
3540
{
36-
s.y -= 4;
41+
tilesprite.y -= 4;
3742
}
38-
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
43+
else if (cursors.down.isDown)
3944
{
40-
s.y += 4;
45+
tilesprite.y += 4;
4146
}
4247

4348
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
3+
4+
var ball;
5+
var tilesprite;
6+
var cursors;
7+
8+
function preload() {
9+
10+
game.load.image('starfield', 'assets/misc/starfield.jpg');
11+
game.load.image('ball', 'assets/sprites/pangball.png');
12+
13+
}
14+
15+
function create() {
16+
17+
ball = game.add.sprite(400, 0, 'ball');
18+
19+
ball.body.gravity.y = 6;
20+
ball.body.bounce.y = 1;
21+
22+
tilesprite = game.add.tileSprite(300, 450, 200, 100, 'starfield');
23+
tilesprite.body.immovable = true;
24+
25+
cursors = game.input.keyboard.createCursorKeys();
26+
27+
}
28+
29+
function update() {
30+
31+
game.physics.collide(ball, tilesprite);
32+
33+
if (cursors.left.isDown)
34+
{
35+
tilesprite.x += 8;
36+
tilesprite.tilePosition.x += 8;
37+
}
38+
else if (cursors.right.isDown)
39+
{
40+
tilesprite.x -= 8;
41+
tilesprite.tilePosition.x -= 8;
42+
}
43+
44+
if (cursors.up.isDown)
45+
{
46+
tilesprite.tilePosition.y += 8;
47+
}
48+
else if (cursors.down.isDown)
49+
{
50+
tilesprite.tilePosition.y -= 8;
51+
}
52+
53+
}
54+
55+
function render() {
56+
57+
game.debug.renderSpriteBounds(tilesprite);
58+
59+
}
Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
11

22
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
33

4-
var s;
4+
var tilesprite;
5+
var cursors;
56

67
function preload() {
8+
79
game.load.image('starfield', 'assets/misc/starfield.jpg');
10+
811
}
912

1013
function create() {
11-
s = game.add.tileSprite(0, 0, 800, 600, 'starfield');
14+
15+
tilesprite = game.add.tileSprite(0, 0, 800, 600, 'starfield');
16+
17+
cursors = game.input.keyboard.createCursorKeys();
18+
1219
}
1320

1421
function update() {
1522

16-
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
23+
if (cursors.left.isDown)
1724
{
18-
s.tilePosition.x += 8;
25+
tilesprite.tilePosition.x += 8;
1926
}
20-
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
27+
else if (cursors.right.isDown)
2128
{
22-
s.tilePosition.x -= 8;
29+
tilesprite.tilePosition.x -= 8;
2330
}
2431

25-
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
32+
if (cursors.up.isDown)
2633
{
27-
s.tilePosition.y += 8;
34+
tilesprite.tilePosition.y += 8;
2835
}
29-
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
36+
else if (cursors.down.isDown)
3037
{
31-
s.tilePosition.y -= 8;
38+
tilesprite.tilePosition.y -= 8;
3239
}
3340

3441
}

src/core/Stage.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ Phaser.Stage = function (game, width, height) {
6767
*/
6868
this.aspectRatio = width / height;
6969

70+
/**
71+
* @property {boolean} disableVisibilityChange - By default if the browser tab loses focus the game will pause. You can stop that behaviour by setting this property to true.
72+
* @default
73+
*/
74+
this.disableVisibilityChange = false;
75+
7076
/**
7177
* @property {number} _nextOffsetCheck - The time to run the next offset check.
7278
* @private

src/gameobjects/TileSprite.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,110 @@ Phaser.TileSprite = function (game, x, y, width, height, key, frame) {
5151
*/
5252
this.tilePosition = new Phaser.Point(0, 0);
5353

54+
this.body.width = width;
55+
this.body.height = height;
56+
5457
};
5558

5659
Phaser.TileSprite.prototype = Phaser.Utils.extend(true, PIXI.TilingSprite.prototype, Phaser.Sprite.prototype);
5760
Phaser.TileSprite.prototype.constructor = Phaser.TileSprite;
5861

62+
/**
63+
* Indicates the rotation of the Sprite, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.
64+
* Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement player.angle = 450 is the same as player.angle = 90.
65+
* If you wish to work in radians instead of degrees use the property Sprite.rotation instead.
66+
* @name Phaser.TileSprite#angle
67+
* @property {number} angle - Gets or sets the Sprites angle of rotation in degrees.
68+
*/
69+
Object.defineProperty(Phaser.TileSprite.prototype, 'angle', {
70+
71+
get: function() {
72+
return Phaser.Math.wrapAngle(Phaser.Math.radToDeg(this.rotation));
73+
},
74+
75+
set: function(value) {
76+
this.rotation = Phaser.Math.degToRad(Phaser.Math.wrapAngle(value));
77+
}
78+
79+
});
80+
81+
/**
82+
* @name Phaser.TileSprite#frame
83+
* @property {number} frame - Gets or sets the current frame index and updates the Texture Cache for display.
84+
*/
85+
Object.defineProperty(Phaser.TileSprite.prototype, "frame", {
86+
87+
get: function () {
88+
return this.animations.frame;
89+
},
90+
91+
set: function (value) {
92+
this.animations.frame = value;
93+
}
94+
95+
});
96+
97+
/**
98+
* @name Phaser.TileSprite#frameName
99+
* @property {string} frameName - Gets or sets the current frame name and updates the Texture Cache for display.
100+
*/
101+
Object.defineProperty(Phaser.TileSprite.prototype, "frameName", {
102+
103+
get: function () {
104+
return this.animations.frameName;
105+
},
106+
107+
set: function (value) {
108+
this.animations.frameName = value;
109+
}
110+
111+
});
112+
113+
/**
114+
* @name Phaser.TileSprite#inCamera
115+
* @property {boolean} inCamera - Is this sprite visible to the camera or not?
116+
* @readonly
117+
*/
118+
Object.defineProperty(Phaser.TileSprite.prototype, "inCamera", {
119+
120+
get: function () {
121+
return this._cache.cameraVisible;
122+
}
123+
124+
});
125+
126+
/**
127+
* By default a Sprite won't process any input events at all. By setting inputEnabled to true the Phaser.InputHandler is
128+
* activated for this Sprite instance and it will then start to process click/touch events and more.
129+
*
130+
* @name Phaser.TileSprite#inputEnabled
131+
* @property {boolean} inputEnabled - Set to true to allow this Sprite to receive input events, otherwise false.
132+
*/
133+
Object.defineProperty(Phaser.TileSprite.prototype, "inputEnabled", {
134+
135+
get: function () {
136+
137+
return (this.input.enabled);
138+
139+
},
140+
141+
set: function (value) {
142+
143+
if (value)
144+
{
145+
if (this.input.enabled === false)
146+
{
147+
this.input.start();
148+
}
149+
}
150+
else
151+
{
152+
if (this.input.enabled)
153+
{
154+
this.input.stop();
155+
}
156+
}
157+
158+
}
159+
160+
});

src/input/Pointer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ Phaser.Pointer.prototype = {
207207
}
208208

209209
// Fix to stop rogue browser plugins from blocking the visibility state event
210-
if (this.game.paused === true && this.game.stage.scale.incorrectOrientation === false)
210+
if (this.game.stage.disableVisibilityChange === false && this.game.paused && this.game.stage.scale.incorrectOrientation === false)
211211
{
212212
this.game.paused = false;
213213
return this;

0 commit comments

Comments
 (0)