Skip to content

Commit c5c7547

Browse files
committed
* When a Sprite is destroyed any active filters are removed as well.
* Updated Pixi.js so that removing filters now works correctly without breaking the display list.
1 parent 8f14483 commit c5c7547

4 files changed

Lines changed: 35 additions & 23 deletions

File tree

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,16 @@ New features:
5050

5151
Updates:
5252

53-
* TBC
53+
* When a Sprite is destroyed any active filters are removed as well.
54+
* Updated Pixi.js so that removing filters now works correctly without breaking the display list.
55+
* Phaser.Canvas.create updated to it can be given an ID as the 3rd parameter.
5456

5557
Bug Fixes:
5658

5759
* Cache.getImageKeys returned __missing in the array, now excluded.
5860
* Fixed Group.scale so you can now scale a Group directly.
5961
* Removed World.scale as it was preventing Group.scale from working - you can still scale the world, but you'll need to factor in Input changes yourself.
60-
62+
* Moved 'dirty' flag for Tilemap to a per-layer flag. Fixes #242
6163

6264
You can view the Change Log for all previous versions at https://github.com/photonstorm/phaser/changelog.md
6365

examples/wip/removeFilter.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ function preload() {
1515
function create() {
1616

1717

18+
logo = game.add.sprite(game.world.centerX, game.world.centerY, 'phaser');
19+
logo.anchor.setTo(0.5, 0.5);
20+
1821
background = game.add.sprite(0, 0);
1922
background.width = 800;
2023
background.height = 600;
@@ -24,8 +27,6 @@ function create() {
2427

2528
background.filters = [filter];
2629

27-
logo = game.add.sprite(game.world.centerX, game.world.centerY, 'phaser');
28-
logo.anchor.setTo(0.5, 0.5);
2930

3031
game.input.onDown.add(removeBackground, this);
3132

@@ -41,7 +42,10 @@ function removeBackground() {
4142

4243
console.log('removeBackground');
4344

44-
// background.destroy();
45-
background.removeFilter(filter);
45+
46+
// background.filters = null;
47+
background.destroy();
48+
49+
// console.log(background.filters);
4650

4751
}

src/gameobjects/Sprite.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,11 @@ Phaser.Sprite.prototype.kill = function() {
840840
*/
841841
Phaser.Sprite.prototype.destroy = function() {
842842

843+
if (this.filters)
844+
{
845+
this.filters = null;
846+
}
847+
843848
if (this.group)
844849
{
845850
this.group.remove(this);
@@ -860,13 +865,6 @@ Phaser.Sprite.prototype.destroy = function() {
860865
this.animations.destroy();
861866
}
862867

863-
if (this._filters)
864-
{
865-
console.log('removeFilter', this._filters);
866-
this.removeFilter(this._filters);
867-
console.log(this._filters);
868-
}
869-
870868
this.alive = false;
871869
this.exists = false;
872870
this.visible = false;

src/system/Canvas.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,29 @@
1313
Phaser.Canvas = {
1414

1515
/**
16-
* Creates the <canvas> tag
16+
* Creates a `canvas` DOM element. The element is not automatically added to the document.
1717
*
1818
* @method Phaser.Canvas.create
19-
* @param {number} width - The desired width.
20-
* @param {number} height - The desired height.
21-
* @return {HTMLCanvasElement} The newly created <canvas> tag.
19+
* @param {number} [width=256] - The width of the canvas element.
20+
* @param {number} [height=256] - The height of the canvas element..
21+
* @param {string} [id=''] - If given this will be set as the ID of the canvas element, otherwise no ID will be set.
22+
* @return {HTMLCanvasElement} The newly created canvas element.
2223
*/
23-
create: function (width, height) {
24+
create: function (width, height, id) {
2425

2526
width = width || 256;
2627
height = height || 256;
2728

2829
var canvas = document.createElement('canvas');
30+
31+
if (typeof id === 'string')
32+
{
33+
canvas.id = id;
34+
}
35+
2936
canvas.width = width;
3037
canvas.height = height;
38+
3139
canvas.style.display = 'block';
3240

3341
return canvas;
@@ -137,7 +145,7 @@ Phaser.Canvas = {
137145
*
138146
* @method Phaser.Canvas.addToDOM
139147
* @param {HTMLCanvasElement} canvas - The canvas to set the touch action on.
140-
* @param {string|HTMLElement} parent - The DOM element to add the canvas to. Defaults to ''.
148+
* @param {string|HTMLElement} parent - The DOM element to add the canvas to.
141149
* @param {boolean} overflowHidden - If set to true it will add the overflow='hidden' style to the parent DOM element.
142150
* @return {HTMLCanvasElement} Returns the source canvas.
143151
*/
@@ -149,14 +157,14 @@ Phaser.Canvas = {
149157

150158
if (parent)
151159
{
152-
// hopefully an element ID
153160
if (typeof parent === 'string')
154161
{
162+
// hopefully an element ID
155163
target = document.getElementById(parent);
156164
}
157-
// quick test for a HTMLelement
158165
else if (typeof parent === 'object' && parent.nodeType === 1)
159166
{
167+
// quick test for a HTMLelement
160168
target = parent;
161169
}
162170

@@ -166,8 +174,8 @@ Phaser.Canvas = {
166174
}
167175
}
168176

169-
// fallback, covers an invalid ID and a none HTMLelement object
170-
if(!target)
177+
// Fallback, covers an invalid ID and a non HTMLelement object
178+
if (!target)
171179
{
172180
target = document.body;
173181
}

0 commit comments

Comments
 (0)