Skip to content

Commit 163a6c4

Browse files
committed
Updated to Pixi 2.0.0-dev.
1 parent 0c54380 commit 163a6c4

63 files changed

Lines changed: 2350 additions & 951 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Version 2.1.3 - "Ravinda" - in development
7575

7676
### New Features
7777

78+
* Updated to Pixi v2.0.0
7879

7980
### Updates
8081

src/pixi/InteractionManager.js

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ PIXI.InteractionManager = function(stage)
100100
*
101101
*/
102102
this.mouseOut = false;
103+
104+
this.resolution = 1;
103105
};
104106

105107
// constructor
@@ -158,6 +160,7 @@ PIXI.InteractionManager.prototype.collectInteractiveSprite = function(displayObj
158160
PIXI.InteractionManager.prototype.setTarget = function(target)
159161
{
160162
this.target = target;
163+
this.resolution = target.resolution;
161164

162165
//check if the dom element has been set. If it has don't do anything
163166
if( this.interactionDOMElement === null ) {
@@ -340,8 +343,8 @@ PIXI.InteractionManager.prototype.onMouseMove = function(event)
340343
// TODO optimize by not check EVERY TIME! maybe half as often? //
341344
var rect = this.interactionDOMElement.getBoundingClientRect();
342345

343-
this.mouse.global.x = (event.clientX - rect.left) * (this.target.width / rect.width);
344-
this.mouse.global.y = (event.clientY - rect.top) * ( this.target.height / rect.height);
346+
this.mouse.global.x = (event.clientX - rect.left) * (this.target.width / rect.width) / this.resolution;
347+
this.mouse.global.y = (event.clientY - rect.top) * ( this.target.height / rect.height) / this.resolution;
345348

346349
var length = this.interactiveItems.length;
347350

@@ -528,8 +531,7 @@ PIXI.InteractionManager.prototype.hitTest = function(item, interactionData)
528531

529532
// temp fix for if the element is in a non visible
530533

531-
var isSprite = (item instanceof PIXI.Sprite),
532-
worldTransform = item.worldTransform,
534+
var worldTransform = item.worldTransform, i,
533535
a00 = worldTransform.a, a01 = worldTransform.b, a02 = worldTransform.tx,
534536
a10 = worldTransform.c, a11 = worldTransform.d, a12 = worldTransform.ty,
535537
id = 1 / (a00 * a11 + a01 * -a10),
@@ -550,7 +552,7 @@ PIXI.InteractionManager.prototype.hitTest = function(item, interactionData)
550552
return false;
551553
}
552554
// a sprite with no hitarea defined
553-
else if(isSprite)
555+
else if(item instanceof PIXI.Sprite)
554556
{
555557
var width = item.texture.frame.width,
556558
height = item.texture.frame.height,
@@ -569,10 +571,29 @@ PIXI.InteractionManager.prototype.hitTest = function(item, interactionData)
569571
}
570572
}
571573
}
574+
else if(item instanceof PIXI.Graphics)
575+
{
576+
var graphicsData = item.graphicsData;
577+
for (i = 0; i < graphicsData.length; i++)
578+
{
579+
var data = graphicsData[i];
580+
if(!data.fill)continue;
581+
582+
// only deal with fills..
583+
if(data.shape)
584+
{
585+
if(data.shape.contains(x, y))
586+
{
587+
interactionData.target = item;
588+
return true;
589+
}
590+
}
591+
}
592+
}
572593

573594
var length = item.children.length;
574595

575-
for (var i = 0; i < length; i++)
596+
for (i = 0; i < length; i++)
576597
{
577598
var tempItem = item.children[i];
578599
var hit = this.hitTest(tempItem, interactionData);
@@ -613,8 +634,8 @@ PIXI.InteractionManager.prototype.onTouchMove = function(event)
613634
touchData.originalEvent = event || window.event;
614635

615636
// update the touch position
616-
touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
617-
touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height);
637+
touchData.global.x = ( (touchEvent.clientX - rect.left) * (this.target.width / rect.width) ) / this.resolution;
638+
touchData.global.y = ( (touchEvent.clientY - rect.top) * (this.target.height / rect.height) ) / this.resolution;
618639
if(navigator.isCocoonJS && !rect.left && !rect.top && !event.target.style.width && !event.target.style.height) {
619640
//Support for CocoonJS fullscreen scale modes
620641
touchData.global.x = touchEvent.clientX;
@@ -658,8 +679,8 @@ PIXI.InteractionManager.prototype.onTouchStart = function(event)
658679
touchData.originalEvent = event || window.event;
659680

660681
this.touchs[touchEvent.identifier] = touchData;
661-
touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
662-
touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height);
682+
touchData.global.x = ( (touchEvent.clientX - rect.left) * (this.target.width / rect.width) ) / this.resolution;
683+
touchData.global.y = ( (touchEvent.clientY - rect.top) * (this.target.height / rect.height) ) / this.resolution;
663684
if(navigator.isCocoonJS && !rect.left && !rect.top && !event.target.style.width && !event.target.style.height) {
664685
//Support for CocoonJS fullscreen scale modes
665686
touchData.global.x = touchEvent.clientX;
@@ -714,8 +735,8 @@ PIXI.InteractionManager.prototype.onTouchEnd = function(event)
714735
var touchEvent = changedTouches[i];
715736
var touchData = this.touchs[touchEvent.identifier];
716737
var up = false;
717-
touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
718-
touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height);
738+
touchData.global.x = ( (touchEvent.clientX - rect.left) * (this.target.width / rect.width) ) / this.resolution;
739+
touchData.global.y = ( (touchEvent.clientY - rect.top) * (this.target.height / rect.height) ) / this.resolution;
719740
if(navigator.isCocoonJS && !rect.left && !rect.top && !event.target.style.width && !event.target.style.height) {
720741
//Support for CocoonJS fullscreen scale modes
721742
touchData.global.x = touchEvent.clientX;

src/pixi/Pixi.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ PIXI.WEBGL_RENDERER = 0;
1616
PIXI.CANVAS_RENDERER = 1;
1717

1818
// useful for testing against if your lib is using pixi.
19-
PIXI.VERSION = "v1.6.1";
19+
PIXI.VERSION = "v2.0.0";
2020

2121

2222
// the various blend modes supported by pixi
@@ -65,12 +65,25 @@ else
6565
PIXI.INTERACTION_FREQUENCY = 30;
6666
PIXI.AUTO_PREVENT_DEFAULT = true;
6767

68+
PIXI.PI_2 = Math.PI * 2;
6869
PIXI.RAD_TO_DEG = 180 / Math.PI;
6970
PIXI.DEG_TO_RAD = Math.PI / 180;
7071

72+
PIXI.RETINA_PREFIX = "@2x";
73+
//PIXI.SCALE_PREFIX "@x%%";
7174

7275
PIXI.dontSayHello = false;
7376

77+
78+
PIXI.defaultRenderOptions = {
79+
view:null,
80+
transparent:false,
81+
antialias:false,
82+
preserveDrawingBuffer:false,
83+
resolution:1,
84+
clearBeforeRender:true
85+
}
86+
7487
PIXI.sayHello = function (type)
7588
{
7689
if(PIXI.dontSayHello)return;

src/pixi/display/DisplayObject.js

Lines changed: 76 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -449,39 +449,67 @@ Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', {
449449
*/
450450
PIXI.DisplayObject.prototype.updateTransform = function()
451451
{
452-
// TODO OPTIMIZE THIS!! with dirty
453-
if(this.rotation !== this.rotationCache)
454-
{
455-
456-
this.rotationCache = this.rotation;
457-
this._sr = Math.sin(this.rotation);
458-
this._cr = Math.cos(this.rotation);
459-
}
452+
// create some matrix refs for easy access
453+
var pt = this.parent.worldTransform;
454+
var wt = this.worldTransform;
460455

461-
// var localTransform = this.localTransform//.toArray();
462-
var parentTransform = this.parent.worldTransform;//.toArray();
463-
var worldTransform = this.worldTransform;//.toArray();
456+
// temporary matrix variables
457+
var a, b, c, d, tx, ty;
464458

465-
var px = this.pivot.x;
466-
var py = this.pivot.y;
459+
// TODO create a const for 2_PI
460+
// so if rotation is between 0 then we can simplify the multiplication process..
461+
if(this.rotation % PIXI.PI_2)
462+
{
463+
// check to see if the rotation is the same as the previous render. This means we only need to use sin and cos when rotation actually changes
464+
if(this.rotation !== this.rotationCache)
465+
{
466+
this.rotationCache = this.rotation;
467+
this._sr = Math.sin(this.rotation);
468+
this._cr = Math.cos(this.rotation);
469+
}
467470

468-
var a00 = this._cr * this.scale.x,
469-
a01 = -this._sr * this.scale.y,
470-
a10 = this._sr * this.scale.x,
471-
a11 = this._cr * this.scale.y,
472-
a02 = this.position.x - a00 * px - py * a01,
473-
a12 = this.position.y - a11 * py - px * a10,
474-
b00 = parentTransform.a, b01 = parentTransform.b,
475-
b10 = parentTransform.c, b11 = parentTransform.d;
471+
// get the matrix values of the displayobject based on its transform properties..
472+
a = this._cr * this.scale.x;
473+
b = this._sr * this.scale.x;
474+
c = -this._sr * this.scale.y;
475+
d = this._cr * this.scale.y;
476+
tx = this.position.x;
477+
ty = this.position.y;
478+
479+
// check for pivot.. not often used so geared towards that fact!
480+
if(this.pivot.x || this.pivot.y)
481+
{
482+
tx -= this.pivot.x * a + this.pivot.y * c;
483+
ty -= this.pivot.x * b + this.pivot.y * d;
484+
}
476485

477-
worldTransform.a = b00 * a00 + b01 * a10;
478-
worldTransform.b = b00 * a01 + b01 * a11;
479-
worldTransform.tx = b00 * a02 + b01 * a12 + parentTransform.tx;
486+
// concat the parent matrix with the objects transform.
487+
wt.a = a * pt.a + b * pt.c;
488+
wt.b = a * pt.b + b * pt.d;
489+
wt.c = c * pt.a + d * pt.c;
490+
wt.d = c * pt.b + d * pt.d;
491+
wt.tx = tx * pt.a + ty * pt.c + pt.tx;
492+
wt.ty = tx * pt.b + ty * pt.d + pt.ty;
480493

481-
worldTransform.c = b10 * a00 + b11 * a10;
482-
worldTransform.d = b10 * a01 + b11 * a11;
483-
worldTransform.ty = b10 * a02 + b11 * a12 + parentTransform.ty;
494+
495+
}
496+
else
497+
{
498+
// lets do the fast version as we know there is no rotation..
499+
a = this.scale.x;
500+
d = this.scale.y;
501+
tx = this.position.x - this.pivot.x * a;
502+
ty = this.position.y - this.pivot.y * d;
503+
504+
wt.a = pt.a * a;
505+
wt.b = pt.b * d;
506+
wt.c = pt.c * a;
507+
wt.d = pt.d * d;
508+
wt.tx = tx * pt.a + ty * pt.c + pt.tx;
509+
wt.ty = tx * pt.b + ty * pt.d + pt.ty;
510+
}
484511

512+
// multiply the alphas..
485513
this.worldAlpha = this.alpha * this.parent.worldAlpha;
486514
};
487515

@@ -520,11 +548,20 @@ PIXI.DisplayObject.prototype.setStageReference = function(stage)
520548
if(this._interactive)this.stage.dirty = true;
521549
};
522550

523-
PIXI.DisplayObject.prototype.generateTexture = function(renderer)
551+
/**
552+
* Useful function that returns a texture of the displayObject object that can then be used to create sprites
553+
* This can be quite useful if your displayObject is static / complicated and needs to be reused multiple times.
554+
*
555+
* @method generateTexture
556+
* @param resolution {Number} The resolution of the texture being generated
557+
* @param scaleMode {Number} Should be one of the PIXI.scaleMode consts
558+
* @return {Texture} a texture of the graphics object
559+
*/
560+
PIXI.DisplayObject.prototype.generateTexture = function(resolution, scaleMode, renderer)
524561
{
525562
var bounds = this.getLocalBounds();
526563

527-
var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, renderer);
564+
var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, renderer, scaleMode, resolution);
528565
renderTexture.render(this, new PIXI.Point(-bounds.x, -bounds.y) );
529566

530567
return renderTexture;
@@ -602,7 +639,11 @@ PIXI.DisplayObject.prototype._generateCachedSprite = function()//renderSession)
602639
this._filters = null;
603640

604641
this._cachedSprite.filters = tempFilters;
605-
this._cachedSprite.texture.render(this, new PIXI.Point(-bounds.x, -bounds.y) );
642+
643+
PIXI.DisplayObject._tempMatrix.tx = -bounds.x;
644+
PIXI.DisplayObject._tempMatrix.ty = -bounds.y;
645+
646+
this._cachedSprite.texture.render(this, PIXI.DisplayObject._tempMatrix );
606647

607648
this._cachedSprite.anchor.x = -( bounds.x / bounds.width );
608649
this._cachedSprite.anchor.y = -( bounds.y / bounds.height );
@@ -652,6 +693,9 @@ PIXI.DisplayObject.prototype._renderCanvas = function(renderSession)
652693
renderSession = renderSession;
653694
};
654695

696+
697+
PIXI.DisplayObject._tempMatrix = new PIXI.Matrix();
698+
655699
/**
656700
* The position of the displayObject on the x axis relative to the local coordinates of the parent.
657701
*
@@ -681,3 +725,5 @@ Object.defineProperty(PIXI.DisplayObject.prototype, 'y', {
681725
this.position.y = value;
682726
}
683727
});
728+
729+

0 commit comments

Comments
 (0)