Skip to content
This repository was archived by the owner on Dec 15, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/core/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,17 @@
scratch.done();
},

/**
* Body#onStep() -> this
*
* Intended to be overridden by subclasses. Called when the associated
* world is stepped.
**/
onStep: function() {
// Override this function to update any associated graphic
return this;
},

/**
* Body#setWorld( world ) -> this
* - world (Object): The world (or null)
Expand All @@ -372,15 +383,21 @@
* Usually this is called internally. Shouldn't be a need to call this yourself usually.
**/
setWorld: function( world ){

if ( this.disconnect && this._world ){
this.disconnect( this._world );
if(this._world) {
this._world.off("step", this.onStep);
if ( this.disconnect ){
this.disconnect( this._world );
}
}

this._world = world;

if ( this.connect && world ){
this.connect( world );
if(this._world) {
this._world.on("step", this.onStep, this);

if ( this.connect ){
this.connect( this._world );
}
}

return this;
Expand Down
21 changes: 21 additions & 0 deletions src/core/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,27 @@
this._integrator.integrate( this._bodies, dt );
},

/** chainable
* Physics.world#stepDelta( dt ) -> this
* - dt (Number): Delta time in ms
*
* Step the world BY a specified change in time
*/
stepDelta: function(dt) {
// If paused or at the first step, calculate the appropriate time
if ( this._paused || this._animTime === undefined ){
this._animTime = this._animTime || Physics.util.ticker.now();
}

// Do nothing while paused
if(this._paused) {
return this;
}

// Otherwise increment the current animation time and step normally
return this.step(this._animTime.valueOf() + dt);
},

/** chainable
* Physics.world#step( [now] ) -> this
* - now (Number): Current unix timestamp
Expand Down
16 changes: 16 additions & 0 deletions src/util/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ Physics.util.clearArray = function clearArray(arr){
return arr;
};

/**
* Physics.util.rad2deg(radians) -> Number
* radians (Number): Radians to convert to degrees
*/
Physics.util.rad2deg = function rad2deg(radians) {
return radians * (180/3.14159265);
};

/**
* Physics.util.deg2rad(radians) -> Number
* degrees (Number): Degrees to convert to radians
*/
Physics.util.deg2rad = function deg2rad(degrees) {
return degrees * (3.14159265/180);
};

/**
* Physics.util.throttle( fn, delay ) -> Function
* - fn (Function): The function to throttle
Expand Down