33var CircleContains = require ( '../../geom/circle/Contains' ) ;
44var Class = require ( '../../utils/Class' ) ;
55var CONST = require ( './const' ) ;
6- // var DegToRad = require('../../math/DegToRad');
7- // var RadToDeg = require('../../math/RadToDeg');
6+ var PhysicsEvent = require ( './events' ) ;
87var Rectangle = require ( '../../geom/rectangle/Rectangle' ) ;
98var RectangleContains = require ( '../../geom/rectangle/Contains' ) ;
109var Vector2 = require ( '../../math/Vector2' ) ;
@@ -81,9 +80,10 @@ var Body = new Class({
8180
8281 this . worldBounce = null ;
8382
84- // this.onWorldBounds = null;
85- // this.onCollide = null;
86- // this.onOverlap = null;
83+ // If true this Body will dispatch events
84+ this . onWorldBounds = false ;
85+ this . onCollide = false ;
86+ this . onOverlap = false ;
8787
8888 this . maxVelocity = new Vector2 ( 10000 , 10000 ) ;
8989
@@ -135,22 +135,14 @@ var Body = new Class({
135135
136136 this . dirty = false ;
137137
138- this . skipQuadTree = false ;
139-
140138 this . syncBounds = false ;
141139
142140 this . isMoving = false ;
143141
144142 this . stopVelocityOnCollide = true ;
145143
146- // this.moveTimer = 0;
147- // this.moveDistance = 0;
148- // this.moveDuration = 0;
149- // this.moveTarget = null;
150- // this.moveEnd = null;
151- // this.onMoveComplete = new Phaser.Signal();
152- // this.movementCallback = null;
153- // this.movementCallbackContext = null;
144+ // read-only
145+ this . physicsType = CONST . BODY ;
154146
155147 this . _reset = true ;
156148
@@ -171,8 +163,6 @@ var Body = new Class({
171163 {
172164 var b = sprite . getBounds ( this . _bounds ) ;
173165
174- // b.ceilAll();
175-
176166 if ( b . width !== this . width || b . height !== this . height )
177167 {
178168 this . width = b . width ;
@@ -244,12 +234,6 @@ var Body = new Class({
244234 this . position . x = sprite . x - sprite . displayOriginX + ( sprite . scaleX * this . offset . x ) ;
245235 this . position . y = sprite . y - sprite . displayOriginY + ( sprite . scaleY * this . offset . y ) ;
246236
247- // this.position.x -= this.sprite.scale.x < 0 ? this.width : 0;
248- // this.position.y -= this.sprite.scale.y < 0 ? this.height : 0;
249-
250- // this.position.x = sprite.x + (sprite.scaleX * this.offset.x);
251- // this.position.y = sprite.y + (sprite.scaleY * this.offset.y);
252-
253237 this . updateCenter ( ) ;
254238
255239 this . rotation = sprite . angle ;
@@ -285,12 +269,10 @@ var Body = new Class({
285269
286270 if ( this . collideWorldBounds )
287271 {
288- this . checkWorldBounds ( ) ;
289-
290- // if (this.checkWorldBounds() && this.onWorldBounds)
291- // {
292- // this.onWorldBounds.dispatch(this.sprite, this.blocked.up, this.blocked.down, this.blocked.left, this.blocked.right);
293- // }
272+ if ( this . checkWorldBounds ( ) && this . onWorldBounds )
273+ {
274+ this . world . events . dispatch ( new PhysicsEvent . WORLD_BOUNDS ( this ) ) ;
275+ }
294276 }
295277 }
296278
@@ -475,14 +457,8 @@ var Body = new Class({
475457
476458 var sprite = this . gameObject ;
477459
478- this . position . x = x + ( sprite . scaleX * this . offset . x ) ;
479- this . position . y = y + ( sprite . scaleY * this . offset . y ) ;
480-
481- // this.position.x = (x - (this.sprite.anchor.x * this.sprite.width)) + this.sprite.scale.x * this.offset.x;
482- // this.position.x -= this.sprite.scale.x < 0 ? this.width : 0;
483-
484- // this.position.y = (y - (this.sprite.anchor.y * this.sprite.height)) + this.sprite.scale.y * this.offset.y;
485- // this.position.y -= this.sprite.scale.y < 0 ? this.height : 0;
460+ this . position . x = x - sprite . displayOriginX + ( sprite . scaleX * this . offset . x ) ;
461+ this . position . y = y - sprite . displayOriginY + ( sprite . scaleY * this . offset . y ) ;
486462
487463 this . prev . x = this . position . x ;
488464 this . prev . y = this . position . y ;
@@ -591,6 +567,174 @@ var Body = new Class({
591567 return ( this . debugShowBody || this . debugShowVelocity ) ;
592568 } ,
593569
570+ setCollideWorldBounds : function ( value )
571+ {
572+ this . collideWorldBounds = value ;
573+
574+ return this ;
575+ } ,
576+
577+ setVelocity : function ( x , y )
578+ {
579+ this . velocity . set ( x , y ) ;
580+
581+ return this ;
582+ } ,
583+
584+ setVelocityX : function ( value )
585+ {
586+ this . velocity . x = value ;
587+
588+ return this ;
589+ } ,
590+
591+ setVelocityY : function ( value )
592+ {
593+ this . velocity . y = value ;
594+
595+ return this ;
596+ } ,
597+
598+ setBounce : function ( x , y )
599+ {
600+ this . bounce . set ( x , y ) ;
601+
602+ return this ;
603+ } ,
604+
605+ setBounceX : function ( value )
606+ {
607+ this . bounce . x = value ;
608+
609+ return this ;
610+ } ,
611+
612+ setBounceY : function ( value )
613+ {
614+ this . bounce . y = value ;
615+
616+ return this ;
617+ } ,
618+
619+ setAcceleration : function ( x , y )
620+ {
621+ this . acceleration . set ( x , y ) ;
622+
623+ return this ;
624+ } ,
625+
626+ setAccelerationX : function ( value )
627+ {
628+ this . acceleration . x = value ;
629+
630+ return this ;
631+ } ,
632+
633+ setAccelerationY : function ( value )
634+ {
635+ this . acceleration . y = value ;
636+
637+ return this ;
638+ } ,
639+
640+ setDrag : function ( x , y )
641+ {
642+ this . drag . set ( x , y ) ;
643+
644+ return this ;
645+ } ,
646+
647+ setDragX : function ( value )
648+ {
649+ this . drag . x = value ;
650+
651+ return this ;
652+ } ,
653+
654+ setDragY : function ( value )
655+ {
656+ this . drag . y = value ;
657+
658+ return this ;
659+ } ,
660+
661+ setGravity : function ( x , y )
662+ {
663+ this . gravity . set ( x , y ) ;
664+
665+ return this ;
666+ } ,
667+
668+ setGravityX : function ( value )
669+ {
670+ this . gravity . x = value ;
671+
672+ return this ;
673+ } ,
674+
675+ setGravityY : function ( value )
676+ {
677+ this . gravity . y = value ;
678+
679+ return this ;
680+ } ,
681+
682+ setFriction : function ( x , y )
683+ {
684+ this . friction . set ( x , y ) ;
685+
686+ return this ;
687+ } ,
688+
689+ setFrictionX : function ( value )
690+ {
691+ this . friction . x = value ;
692+
693+ return this ;
694+ } ,
695+
696+ setFrictionY : function ( value )
697+ {
698+ this . friction . y = value ;
699+
700+ return this ;
701+ } ,
702+
703+ setAngularVelocity : function ( value )
704+ {
705+ this . angularVelocity = value ;
706+
707+ return this ;
708+ } ,
709+
710+ setAngularAcceleration : function ( value )
711+ {
712+ this . angularAcceleration = value ;
713+
714+ return this ;
715+ } ,
716+
717+ setAngularDrag : function ( value )
718+ {
719+ this . angularDrag = value ;
720+
721+ return this ;
722+ } ,
723+
724+ setMass : function ( value )
725+ {
726+ this . mass = value ;
727+
728+ return this ;
729+ } ,
730+
731+ setImmovable : function ( value )
732+ {
733+ this . immovable = value ;
734+
735+ return this ;
736+ } ,
737+
594738 x : {
595739
596740 get : function ( )
0 commit comments