Skip to content

Commit 18c695e

Browse files
committed
PixiPatch and other 1.0.7 features
1 parent 6353d8c commit 18c695e

10 files changed

Lines changed: 413 additions & 26 deletions

File tree

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,19 @@ Version 1.0.7 (in progress in the dev branch)
4242
* Updated ArcadePhysics.separateX/Y to use new body system - much better results now.
4343
* QuadTree bug found in 1.0.5 now fixed. The QuadTree is updated properly now using worldTransform values.
4444
* Fixed the Bounce.In and Bounce.InOut tweens (thanks XekeDeath)
45+
* Renamed Phaser.Text.text to Phaser.Text.content to avoid conflict and overwrite from Pixi local var.
46+
* Renamed Phaser.Text.style to Phaser.Text.font to avoid conflict and overwrite from Pixi local var.
47+
* Phaser.Button now sets useHandCursor to true by default.
48+
* Fixed an issue in Animation.update where if the game was paused it would get an insane delta timer throwing a uuid error.
49+
* Added PixiPatch.js to patch in a few essential features until Pixi is updated.
50+
* Fixed issue in Animation.play where the given frameRate and loop values wouldn't overwrite those set on construction.
51+
* Added Animation.paused - can be set to true/false.
52+
* New: Phaser.Animation.generateFrameNames - really useful when creating animation data from texture atlases using file names, not indexes.
53+
4554

4655
* TODO: addMarker hh:mm:ss:ms
4756
* TODO: Direction constants
57+
* TODO: Camera will adjust core DO. Means scrollFactor will need to be dropped sadly, but there are other ways to emulate its effect.
4858

4959
Version 1.0.6 (September 24th 2013)
5060

examples/input/follow mouse.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
$title = "Follow Mouse";
3+
require('../head.php');
4+
?>
5+
6+
<script type="text/javascript">
7+
8+
(function () {
9+
10+
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
11+
12+
function preload() {
13+
14+
game.load.image('ball', 'assets/sprites/shinyball.png');
15+
16+
}
17+
18+
var sprite;
19+
20+
function create() {
21+
22+
sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'ball');
23+
24+
}
25+
26+
function update() {
27+
28+
// only move when you click
29+
if (game.input.mousePointer.isDown)
30+
{
31+
// 400 is the speed it will move towards the mouse
32+
game.physics.moveTowardsMouse(sprite, 400);
33+
34+
// if it's overlapping the mouse, don't move any more
35+
if (Phaser.Rectangle.contains(sprite.body, game.input.x, game.input.y))
36+
{
37+
sprite.body.velocity.setTo(0, 0);
38+
}
39+
}
40+
else
41+
{
42+
sprite.body.velocity.setTo(0, 0);
43+
}
44+
45+
}
46+
47+
})();
48+
49+
</script>
50+
51+
<?php
52+
require('../foot.php');
53+
?>

src/PixiPatch.js

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
/**
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+
*
7+
* Hopefully we can remove this once Pixi has been updated to support these things.
8+
*/
9+
10+
PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject)
11+
{
12+
// no loger recurrsive!
13+
var transform;
14+
var context = this.context;
15+
16+
context.globalCompositeOperation = 'source-over';
17+
18+
// one the display object hits this. we can break the loop
19+
var testObject = displayObject.last._iNext;
20+
displayObject = displayObject.first;
21+
22+
do
23+
{
24+
transform = displayObject.worldTransform;
25+
26+
if(!displayObject.visible)
27+
{
28+
displayObject = displayObject.last._iNext;
29+
continue;
30+
}
31+
32+
if(!displayObject.renderable || displayObject.alpha == 0)
33+
{
34+
displayObject = displayObject._iNext;
35+
continue;
36+
}
37+
38+
if(displayObject instanceof PIXI.Sprite)
39+
{
40+
var frame = displayObject.texture.frame;
41+
42+
if(frame)
43+
{
44+
context.globalAlpha = displayObject.worldAlpha;
45+
46+
if (displayObject.texture.trimmed)
47+
{
48+
context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2] + displayObject.texture.trim.x, transform[5] + displayObject.texture.trim.y);
49+
}
50+
else
51+
{
52+
context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]);
53+
}
54+
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);
64+
}
65+
}
66+
else if(displayObject instanceof PIXI.Strip)
67+
{
68+
context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5])
69+
this.renderStrip(displayObject);
70+
}
71+
else if(displayObject instanceof PIXI.TilingSprite)
72+
{
73+
context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5])
74+
this.renderTilingSprite(displayObject);
75+
}
76+
else if(displayObject instanceof PIXI.CustomRenderable)
77+
{
78+
displayObject.renderCanvas(this);
79+
}
80+
else if(displayObject instanceof PIXI.Graphics)
81+
{
82+
context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5])
83+
PIXI.CanvasGraphics.renderGraphics(displayObject, context);
84+
}
85+
else if(displayObject instanceof PIXI.FilterBlock)
86+
{
87+
if(displayObject.open)
88+
{
89+
context.save();
90+
91+
var cacheAlpha = displayObject.mask.alpha;
92+
var maskTransform = displayObject.mask.worldTransform;
93+
94+
context.setTransform(maskTransform[0], maskTransform[3], maskTransform[1], maskTransform[4], maskTransform[2], maskTransform[5])
95+
96+
displayObject.mask.worldAlpha = 0.5;
97+
98+
context.worldAlpha = 0;
99+
100+
PIXI.CanvasGraphics.renderGraphicsMask(displayObject.mask, context);
101+
context.clip();
102+
103+
displayObject.mask.worldAlpha = cacheAlpha;
104+
}
105+
else
106+
{
107+
context.restore();
108+
}
109+
}
110+
// count++
111+
displayObject = displayObject._iNext;
112+
113+
114+
}
115+
while(displayObject != testObject)
116+
117+
}
118+
119+
PIXI.WebGLBatch.prototype.update = function()
120+
{
121+
var gl = this.gl;
122+
var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index, index2, index3
123+
124+
var a, b, c, d, tx, ty;
125+
126+
var indexRun = 0;
127+
128+
var displayObject = this.head;
129+
130+
while(displayObject)
131+
{
132+
if(displayObject.vcount === PIXI.visibleCount)
133+
{
134+
width = displayObject.texture.frame.width;
135+
height = displayObject.texture.frame.height;
136+
137+
// TODO trim??
138+
aX = displayObject.anchor.x;// - displayObject.texture.trim.x
139+
aY = displayObject.anchor.y; //- displayObject.texture.trim.y
140+
w0 = width * (1-aX);
141+
w1 = width * -aX;
142+
143+
h0 = height * (1-aY);
144+
h1 = height * -aY;
145+
146+
index = indexRun * 8;
147+
148+
worldTransform = displayObject.worldTransform;
149+
150+
a = worldTransform[0];
151+
b = worldTransform[3];
152+
c = worldTransform[1];
153+
d = worldTransform[4];
154+
tx = worldTransform[2];
155+
ty = worldTransform[5];
156+
157+
if (displayObject.texture.trimmed)
158+
{
159+
tx += displayObject.texture.trim.x;
160+
ty += displayObject.texture.trim.y;
161+
}
162+
163+
this.verticies[index + 0 ] = a * w1 + c * h1 + tx;
164+
this.verticies[index + 1 ] = d * h1 + b * w1 + ty;
165+
166+
this.verticies[index + 2 ] = a * w0 + c * h1 + tx;
167+
this.verticies[index + 3 ] = d * h1 + b * w0 + ty;
168+
169+
this.verticies[index + 4 ] = a * w0 + c * h0 + tx;
170+
this.verticies[index + 5 ] = d * h0 + b * w0 + ty;
171+
172+
this.verticies[index + 6] = a * w1 + c * h0 + tx;
173+
this.verticies[index + 7] = d * h0 + b * w1 + ty;
174+
175+
if(displayObject.updateFrame || displayObject.texture.updateFrame)
176+
{
177+
this.dirtyUVS = true;
178+
179+
var texture = displayObject.texture;
180+
181+
var frame = texture.frame;
182+
var tw = texture.baseTexture.width;
183+
var th = texture.baseTexture.height;
184+
185+
this.uvs[index + 0] = frame.x / tw;
186+
this.uvs[index +1] = frame.y / th;
187+
188+
this.uvs[index +2] = (frame.x + frame.width) / tw;
189+
this.uvs[index +3] = frame.y / th;
190+
191+
this.uvs[index +4] = (frame.x + frame.width) / tw;
192+
this.uvs[index +5] = (frame.y + frame.height) / th;
193+
194+
this.uvs[index +6] = frame.x / tw;
195+
this.uvs[index +7] = (frame.y + frame.height) / th;
196+
197+
displayObject.updateFrame = false;
198+
}
199+
200+
// TODO this probably could do with some optimisation....
201+
if(displayObject.cacheAlpha != displayObject.worldAlpha)
202+
{
203+
displayObject.cacheAlpha = displayObject.worldAlpha;
204+
205+
var colorIndex = indexRun * 4;
206+
this.colors[colorIndex] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.colors[colorIndex + 3] = displayObject.worldAlpha;
207+
this.dirtyColors = true;
208+
}
209+
}
210+
else
211+
{
212+
index = indexRun * 8;
213+
214+
this.verticies[index + 0 ] = 0;
215+
this.verticies[index + 1 ] = 0;
216+
217+
this.verticies[index + 2 ] = 0;
218+
this.verticies[index + 3 ] = 0;
219+
220+
this.verticies[index + 4 ] = 0;
221+
this.verticies[index + 5 ] = 0;
222+
223+
this.verticies[index + 6] = 0;
224+
this.verticies[index + 7] = 0;
225+
}
226+
227+
indexRun++;
228+
displayObject = displayObject.__next;
229+
}
230+
}

0 commit comments

Comments
 (0)