examples/game/lib/model/player.js
function(posX, posY){

            //Calculate the position deltas while account for zone boundaries
            var zoneWidth = Constants.Zone.WIDTH;
            var zoneHeight = Constants.Zone.HEIGHT;

            var deltaX = posX - this.get("posX");
            if (Math.abs(deltaX) > zoneWidth/2){
                (posX < zoneWidth/2) ? deltaX += zoneWidth : deltaX -= zoneWidth;
            }

            var deltaY = posY - this.get("posY");
            if (Math.abs(deltaY) > zoneHeight/2){
                (posY < zoneHeight/2) ? deltaY += zoneHeight : deltaY -= zoneHeight;
            }

            var data = this.attributes;

            //Update the velocities to move to the correct position by the next update
            var interval = Constants.UPDATE_INTERVAL/1000;
            data.velocityX += deltaX / interval;
            data.velocityY += deltaY / interval;

            //If these changes take us over the maximum velocities, update the constants to allow for it
            this.MAX_VELOCITY_X = Math.max(data.velocityX, Constants.Player.MAX_VELOCITY_X);
            this.MAX_VELOCITY_Y = Math.max(data.velocityY, Constants.Player.MAX_VELOCITY_Y);

            return this;
        }
function(posX, posY){

            //Calculate the position deltas while account for zone boundaries
            var zoneWidth = Constants.Zone.WIDTH;
            var zoneHeight = Constants.Zone.HEIGHT;

            var deltaX = posX - this.get("posX");
            if (Math.abs(deltaX) > zoneWidth/2){
                (posX < zoneWidth/2) ? deltaX += zoneWidth : deltaX -= zoneWidth;
            }

            var deltaY = posY - this.get("posY");
            if (Math.abs(deltaY) > zoneHeight/2){
                (posY < zoneHeight/2) ? deltaY += zoneHeight : deltaY -= zoneHeight;
            }

            var data = this.attributes;

            //Update the velocities to move to the correct position by the next update
            var interval = Constants.UPDATE_INTERVAL/1000;
            data.velocityX += deltaX / interval;
            data.velocityY += deltaY / interval;

            //If these changes take us over the maximum velocities, update the constants to allow for it
            this.MAX_VELOCITY_X = Math.max(data.velocityX, Constants.Player.MAX_VELOCITY_X);
            this.MAX_VELOCITY_Y = Math.max(data.velocityY, Constants.Player.MAX_VELOCITY_Y);

            return this;
        }
function ( posX , posY ) { //Calculate the position deltas while account for zone boundaries var zoneWidth = Constants . Zone . WIDTH ; var zoneHeight = Constants . Zone . HEIGHT ; var deltaX = posX - this . get ( "posX" ) ; if ( Math . abs ( deltaX ) > zoneWidth / 2 ) { ( posX < zoneWidth / 2 ) ? deltaX += zoneWidth : deltaX -= zoneWidth ; } var deltaY = posY - this . get ( "posY" ) ; if ( Math . abs ( deltaY ) > zoneHeight / 2 ) { ( posY < zoneHeight / 2 ) ? deltaY += zoneHeight : deltaY -= zoneHeight ; } var data = this . attributes ; //Update the velocities to move to the correct position by the next update var interval = Constants . UPDATE_INTERVAL / 1000 ; data . velocityX += deltaX / interval ; data . velocityY += deltaY / interval ; //If these changes take us over the maximum velocities, update the constants to allow for it this . MAX_VELOCITY_X = Math . max ( data . velocityX , Constants . Player . MAX_VELOCITY_X ) ; this . MAX_VELOCITY_Y = Math . max ( data . velocityY , Constants . Player . MAX_VELOCITY_Y ) ; return this ; }
Ease a player to a new position, by adding an auxiliary angle and velocity to update by.
This function can serve as a "dead reckoning algorithm" to smooth difference between positions on the client and server
@param {number} posX
@param {number} posY
@returns {*}
Ease a player to a new position by adding an auxiliary angle and velocity to update by . This function can serve as a dead reckoning algorithm to smooth difference between positions on the client and server