Skip to content

Commit a5f2d65

Browse files
committed
Fixing a few more Pixi issues.
1 parent 7ad4164 commit a5f2d65

6 files changed

Lines changed: 166 additions & 97 deletions

File tree

examples/wip/bmd2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

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

44
function preload() {
55

examples/wip/gc1.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
3+
4+
function preload() {
5+
}
6+
7+
function create() {
8+
}
9+
10+
function update() {
11+
}
12+
13+
function render() {
14+
}

src/PixiPatch.js

Lines changed: 72 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,139 @@
11
/**
2-
* We're replacing a couple of Pixi's methods here to fix or add some vital functionality:
3-
*
4-
* 1) Added support for Trimmed sprite sheets
5-
* 2) Skip display objects with an alpha of zero
2+
* We're replacing a couple of Pixi's methods here to fix or add some vital functionality:
3+
*
4+
* 1) Added support for Trimmed sprite sheets
5+
* 2) Skip display objects with an alpha of zero
6+
* 3) Avoid Style Recalculation from the incorrect bgcolor value
7+
*
8+
* Hopefully we can remove this once Pixi has been updated to support these things.
9+
*/
10+
11+
/**
12+
* Renders the stage to its canvas view
613
*
7-
* Hopefully we can remove this once Pixi has been updated to support these things.
14+
* @method render
15+
* @param stage {Stage} the Stage element to be rendered
816
*/
9-
10-
PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject)
17+
PIXI.CanvasRenderer.prototype.render = function(stage)
1118
{
12-
// no loger recurrsive!
13-
var transform;
14-
var context = this.context;
19+
PIXI.texturesToUpdate.length = 0;
20+
PIXI.texturesToDestroy.length = 0;
21+
22+
PIXI.visibleCount++;
23+
stage.updateTransform();
1524

16-
context.globalCompositeOperation = 'source-over';
25+
// update the background color
26+
// if(this.view.style.backgroundColor!=stage.backgroundColorString && !this.transparent)this.view.style.backgroundColor = stage.backgroundColorString;
27+
28+
this.context.setTransform(1, 0, 0, 1, 0, 0);
29+
this.context.clearRect(0, 0, this.width, this.height)
30+
this.renderDisplayObject(stage);
31+
32+
// Remove frame updates
33+
if (PIXI.Texture.frameUpdates.length > 0)
34+
{
35+
PIXI.Texture.frameUpdates.length = 0;
36+
}
1737

18-
// one the display object hits this. we can break the loop
38+
}
39+
40+
PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject)
41+
{
42+
// Once the display object hits this we can break the loop
1943
var testObject = displayObject.last._iNext;
2044
displayObject = displayObject.first;
2145

2246
do
2347
{
24-
transform = displayObject.worldTransform;
48+
//transform = displayObject.worldTransform;
2549

26-
if(!displayObject.visible)
50+
if (!displayObject.visible)
2751
{
2852
displayObject = displayObject.last._iNext;
2953
continue;
3054
}
3155

32-
if(!displayObject.renderable || displayObject.alpha == 0)
56+
if (!displayObject.renderable || displayObject.alpha == 0)
3357
{
3458
displayObject = displayObject._iNext;
3559
continue;
3660
}
3761

38-
if(displayObject instanceof PIXI.Sprite)
62+
if (displayObject instanceof PIXI.Sprite)
3963
{
40-
var frame = displayObject.texture.frame;
64+
// var frame = displayObject.texture.frame;
4165

42-
if(frame)
66+
if (displayObject.texture.frame)
4367
{
44-
context.globalAlpha = displayObject.worldAlpha;
68+
this.context.globalAlpha = displayObject.worldAlpha;
4569

4670
if (displayObject.texture.trimmed)
4771
{
48-
context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2] + displayObject.texture.trim.x, transform[5] + displayObject.texture.trim.y);
72+
this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2] + displayObject.texture.trim.x, displayObject.worldTransform[5] + displayObject.texture.trim.y);
4973
}
5074
else
5175
{
52-
context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]);
76+
this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5]);
5377
}
5478

55-
context.drawImage(displayObject.texture.baseTexture.source,
56-
frame.x,
57-
frame.y,
58-
frame.width,
59-
frame.height,
60-
(displayObject.anchor.x) * -frame.width,
61-
(displayObject.anchor.y) * -frame.height,
62-
frame.width,
63-
frame.height);
79+
this.context.drawImage(
80+
displayObject.texture.baseTexture.source,
81+
displayObject.texture.frame.x,
82+
displayObject.texture.frame.y,
83+
displayObject.texture.frame.width,
84+
displayObject.texture.frame.height,
85+
(displayObject.anchor.x) * -displayObject.texture.frame.width,
86+
(displayObject.anchor.y) * -displayObject.texture.frame.height,
87+
displayObject.texture.frame.width,
88+
displayObject.texture.frame.height);
6489
}
6590
}
66-
else if(displayObject instanceof PIXI.Strip)
91+
else if (displayObject instanceof PIXI.Strip)
6792
{
68-
context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5])
93+
this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5])
6994
this.renderStrip(displayObject);
7095
}
71-
else if(displayObject instanceof PIXI.TilingSprite)
96+
else if (displayObject instanceof PIXI.TilingSprite)
7297
{
73-
context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5])
98+
this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5])
7499
this.renderTilingSprite(displayObject);
75100
}
76-
else if(displayObject instanceof PIXI.CustomRenderable)
101+
else if (displayObject instanceof PIXI.CustomRenderable)
77102
{
78103
displayObject.renderCanvas(this);
79104
}
80-
else if(displayObject instanceof PIXI.Graphics)
105+
else if (displayObject instanceof PIXI.Graphics)
81106
{
82-
context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5])
83-
PIXI.CanvasGraphics.renderGraphics(displayObject, context);
107+
this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5])
108+
PIXI.CanvasGraphics.renderGraphics(displayObject, this.context);
84109
}
85-
else if(displayObject instanceof PIXI.FilterBlock)
110+
else if (displayObject instanceof PIXI.FilterBlock)
86111
{
87-
if(displayObject.open)
112+
if (displayObject.open)
88113
{
89-
context.save();
114+
this.context.save();
90115

91116
var cacheAlpha = displayObject.mask.alpha;
92117
var maskTransform = displayObject.mask.worldTransform;
93118

94-
context.setTransform(maskTransform[0], maskTransform[3], maskTransform[1], maskTransform[4], maskTransform[2], maskTransform[5])
119+
this.context.setTransform(maskTransform[0], maskTransform[3], maskTransform[1], maskTransform[4], maskTransform[2], maskTransform[5])
95120

96121
displayObject.mask.worldAlpha = 0.5;
97122

98-
context.worldAlpha = 0;
123+
this.context.worldAlpha = 0;
99124

100-
PIXI.CanvasGraphics.renderGraphicsMask(displayObject.mask, context);
101-
context.clip();
125+
PIXI.CanvasGraphics.renderGraphicsMask(displayObject.mask, this.context);
126+
this.context.clip();
102127

103128
displayObject.mask.worldAlpha = cacheAlpha;
104129
}
105130
else
106131
{
107-
context.restore();
132+
this.context.restore();
108133
}
109134
}
110-
// count++
135+
// count++
111136
displayObject = displayObject._iNext;
112-
113-
114137
}
115138
while(displayObject != testObject)
116139

src/gameobjects/BitmapData.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,31 @@ Phaser.BitmapData = function (game, width, height) {
5454
* @property {array} imageData - The canvas image data.
5555
*/
5656
this.imageData = this.context.getImageData(0, 0, width, height);
57-
57+
58+
this.pixels = new Int32Array(this.imageData.data.buffer);
59+
5860
/**
5961
* @property {Uint8ClampedArray} data8 - A uint8 clamped view on the buffer.
6062
*/
61-
this.data8 = new Uint8ClampedArray(this.imageData.buffer);
63+
// this.data8 = new Uint8ClampedArray(this.imageData.buffer);
6264

6365
/**
6466
* @property {Uint32Array} data32 - A Uint32 view on the buffer.
6567
*/
66-
this.data32 = new Uint32Array(this.imageData.buffer);
68+
// this.data32 = new Uint32Array(this.imageData.buffer);
6769

6870
// Little or big-endian?
69-
this.data32[1] = 0x0a0b0c0d;
71+
// this.data32[1] = 0x0a0b0c0d;
7072

7173
/**
7274
* @property {boolean} isLittleEndian - .
7375
*/
7476
this.isLittleEndian = true;
7577

76-
if (this.data32[4] === 0x0a && this.data32[5] === 0x0b && this.data32[6] === 0x0c && this.data32[7] === 0x0d)
77-
{
78-
this.isLittleEndian = false;
79-
}
78+
// if (this.data32[4] === 0x0a && this.data32[5] === 0x0b && this.data32[6] === 0x0c && this.data32[7] === 0x0d)
79+
// {
80+
// this.isLittleEndian = false;
81+
// }
8082

8183
/**
8284
* @property {PIXI.BaseTexture} baseTexture - The PIXI.BaseTexture.
@@ -150,8 +152,10 @@ Phaser.BitmapData.prototype = {
150152
refreshBuffer: function () {
151153

152154
this.imageData = this.context.getImageData(0, 0, this.width, this.height);
153-
this.data8 = new Uint8ClampedArray(this.imageData.buffer);
154-
this.data32 = new Uint32Array(this.imageData.buffer);
155+
this.pixels = new Int32Array(this.imageData.data.buffer);
156+
157+
// this.data8 = new Uint8ClampedArray(this.imageData.buffer);
158+
// this.data32 = new Uint32Array(this.imageData.buffer);
155159

156160
},
157161

@@ -169,6 +173,9 @@ Phaser.BitmapData.prototype = {
169173

170174
if (x >= 0 && x <= this.width && y >= 0 && y <= this.height)
171175
{
176+
this.pixels[y * this.width + x] = (alpha << 24) | (blue << 16) | (green << 8) | red;
177+
178+
/*
172179
if (this.isLittleEndian)
173180
{
174181
this.data32[y * this.width + x] = (alpha << 24) | (blue << 16) | (green << 8) | red;
@@ -177,8 +184,9 @@ Phaser.BitmapData.prototype = {
177184
{
178185
this.data32[y * this.width + x] = (red << 24) | (green << 16) | (blue << 8) | alpha;
179186
}
187+
*/
180188

181-
this.imageData.data.set(this.data8);
189+
// this.imageData.data.set(this.data8);
182190

183191
this.context.putImageData(this.imageData, 0, 0);
184192

src/input/Mouse.js

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,30 @@ Phaser.Mouse = function (game) {
6969
*/
7070
this.pointerLock = new Phaser.Signal;
7171

72+
/**
73+
* The browser mouse event.
74+
* @property {MouseEvent} event
75+
*/
76+
this.event;
77+
78+
/**
79+
* @property {function} _onMouseDown
80+
* @private
81+
*/
82+
this._onMouseDown;
83+
84+
/**
85+
* @property {function} _onMouseMove
86+
* @private
87+
*/
88+
this._onMouseMove;
89+
90+
/**
91+
* @property {function} _onMouseUp
92+
* @private
93+
*/
94+
this._onMouseUp;
95+
7296
};
7397

7498
/**
@@ -122,9 +146,13 @@ Phaser.Mouse.prototype = {
122146
return _this.onMouseUp(event);
123147
};
124148

125-
this.game.renderer.view.addEventListener('mousedown', this._onMouseDown, true);
126-
this.game.renderer.view.addEventListener('mousemove', this._onMouseMove, true);
127-
this.game.renderer.view.addEventListener('mouseup', this._onMouseUp, true);
149+
// this.game.renderer.view.addEventListener('mousedown', this._onMouseDown, true);
150+
// this.game.renderer.view.addEventListener('mousemove', this._onMouseMove, true);
151+
// this.game.renderer.view.addEventListener('mouseup', this._onMouseUp, true);
152+
153+
document.addEventListener('mousedown', this._onMouseDown, true);
154+
document.addEventListener('mousemove', this._onMouseMove, true);
155+
document.addEventListener('mouseup', this._onMouseUp, true);
128156

129157
},
130158

@@ -135,20 +163,11 @@ Phaser.Mouse.prototype = {
135163
*/
136164
onMouseDown: function (event) {
137165

166+
this.event = event;
167+
138168
event.preventDefault();
139169

140-
if (event.which === 1)
141-
{
142-
this.button = Phaser.Mouse.LEFT_BUTTON;
143-
}
144-
else if (event.which === 2)
145-
{
146-
this.button = Phaser.Mouse.MIDDLE_BUTTON;
147-
}
148-
else if (event.which === 3)
149-
{
150-
this.button = Phaser.Mouse.RIGHT_BUTTON;
151-
}
170+
this.button = event.which;
152171

153172
if (this.mouseDownCallback)
154173
{
@@ -173,6 +192,8 @@ Phaser.Mouse.prototype = {
173192
*/
174193
onMouseMove: function (event) {
175194

195+
this.event = event;
196+
176197
event.preventDefault();
177198

178199
if (this.mouseMoveCallback)
@@ -198,6 +219,8 @@ Phaser.Mouse.prototype = {
198219
*/
199220
onMouseUp: function (event) {
200221

222+
this.event = event;
223+
201224
event.preventDefault();
202225

203226
this.button = Phaser.Mouse.NO_BUTTON;
@@ -293,9 +316,13 @@ Phaser.Mouse.prototype = {
293316
*/
294317
stop: function () {
295318

296-
this.game.stage.canvas.removeEventListener('mousedown', this._onMouseDown, true);
297-
this.game.stage.canvas.removeEventListener('mousemove', this._onMouseMove, true);
298-
this.game.stage.canvas.removeEventListener('mouseup', this._onMouseUp, true);
319+
// this.game.stage.canvas.removeEventListener('mousedown', this._onMouseDown, true);
320+
// this.game.stage.canvas.removeEventListener('mousemove', this._onMouseMove, true);
321+
// this.game.stage.canvas.removeEventListener('mouseup', this._onMouseUp, true);
322+
323+
document.removeEventListener('mousedown', this._onMouseDown, true);
324+
document.removeEventListener('mousemove', this._onMouseMove, true);
325+
document.removeEventListener('mouseup', this._onMouseUp, true);
299326

300327
}
301328

0 commit comments

Comments
 (0)