mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 06:28:30 +00:00
Acceleration tested and working fine. Proper accurate friction added and working really nicely, so much better than 'drag' used to. Considering removing drag, although will break the API history.
This commit is contained in:
parent
754219a978
commit
10d105d5ce
4 changed files with 47 additions and 110 deletions
|
@ -29,6 +29,7 @@ function create() {
|
|||
car.body.collideWorldBounds = true;
|
||||
car.body.bounce.setTo(0.8, 0.8);
|
||||
car.body.allowRotation = true;
|
||||
car.body.friction = 10;
|
||||
|
||||
// car.body.drag.x = 10;
|
||||
// car.body.drag.y = 10;
|
||||
|
@ -50,36 +51,36 @@ function start() {
|
|||
|
||||
function update() {
|
||||
|
||||
if (car.x >= 400 && car.body.velocity.x > 0)
|
||||
{
|
||||
car.body.velocity.x = 0;
|
||||
car.body.acceleration.x = 0;
|
||||
var total = game.time.now - s;
|
||||
console.log(game.time.physicsElapsed);
|
||||
console.log('total ms', total, 'px/sec', car.x/(total/1000));
|
||||
}
|
||||
// if (car.x >= 400 && car.body.velocity.x > 0)
|
||||
// {
|
||||
// car.body.velocity.x = 0;
|
||||
// car.body.acceleration.x = 0;
|
||||
// var total = game.time.now - s;
|
||||
// console.log(game.time.physicsElapsed);
|
||||
// console.log('total ms', total, 'px/sec', car.x/(total/1000));
|
||||
// }
|
||||
|
||||
// car.body.velocity.x = 0;
|
||||
// car.body.velocity.y = 0;
|
||||
// car.body.angularVelocity = 0;
|
||||
car.body.angularVelocity = 0;
|
||||
|
||||
// car.body.acceleration.x = 0;
|
||||
// car.body.acceleration.y = 0;
|
||||
car.body.acceleration.x = 0;
|
||||
car.body.acceleration.y = 0;
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
car.body.angularVelocity = -200;
|
||||
// car.body.acceleration.x = -10;
|
||||
// car.body.acceleration.x = -100;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
car.body.angularVelocity = 200;
|
||||
// car.body.acceleration.x = 10;
|
||||
// car.body.acceleration.x = 100;
|
||||
}
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
// game.physics.accelerationFromRotation(car.rotation, 10, car.body.acceleration);
|
||||
game.physics.accelerationFromRotation(car.rotation, 400, car.body.acceleration);
|
||||
|
||||
// car.body.acceleration.x = 10;
|
||||
// car.body.acceleration.copyFrom(game.physics.velocityFromAngle(car.angle, 30));
|
||||
|
@ -96,6 +97,7 @@ function update() {
|
|||
|
||||
function render() {
|
||||
|
||||
game.debug.renderSpriteInfo(car, 32, 32);
|
||||
// game.debug.renderSpriteInfo(car, 32, 32);
|
||||
game.debug.renderBodyInfo(car, 16, 24);
|
||||
|
||||
}
|
||||
|
|
|
@ -40,9 +40,9 @@
|
|||
this.bunny.body.velocity.x = -500;
|
||||
}
|
||||
|
||||
// var melon = this.melonGroup.getFirstExists(true);
|
||||
// melon.x = this.bunny.x;
|
||||
// melon.y = this.bunny.y - 40;
|
||||
var melon = this.melonGroup.getFirstExists(true);
|
||||
melon.x = this.bunny.x;
|
||||
melon.y = this.bunny.y - 40;
|
||||
|
||||
this.carrot.x = this.bunny.x;
|
||||
this.carrot.y = this.bunny.y - 20;
|
||||
|
|
|
@ -315,7 +315,7 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
|||
this._sleepTimer = 0; // ms
|
||||
this._drag = 0;
|
||||
this._debug = 0;
|
||||
// this.friction = 0.99;
|
||||
this.friction = 0.9;
|
||||
// this._debug = 0;
|
||||
|
||||
/**
|
||||
|
@ -387,7 +387,7 @@ Phaser.Physics.Arcade.Body.prototype = {
|
|||
this.preY = (this.sprite.world.y - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
this.preRotation = this.sprite.angle;
|
||||
|
||||
if (this.canSleep && this.sleeping && this.velocity.equals(this.prevVelocity) === false)
|
||||
if (this.canSleep && this.sleeping && (this.velocity.equals(this.prevVelocity) === false || this.acceleration.isZero() === false))
|
||||
{
|
||||
this.sleeping = false;
|
||||
this._sleepTimer = 0;
|
||||
|
@ -450,33 +450,19 @@ Phaser.Physics.Arcade.Body.prototype = {
|
|||
|
||||
applyMotion: function () {
|
||||
|
||||
// Apply drag - this should be proportionally applied, not linearly like below
|
||||
if (this.drag.x !== 0 && this.acceleration.x === 0)
|
||||
if (this.friction > 0 && this.acceleration.isZero())
|
||||
{
|
||||
this._drag = this.drag.x * this.game.time.physicsElapsed;
|
||||
if (this.speed > this.friction)
|
||||
{
|
||||
this.speed -= this.friction;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.speed = 0;
|
||||
}
|
||||
|
||||
if (this.velocity.x > 0)
|
||||
{
|
||||
this.velocity.x -= this._drag;
|
||||
}
|
||||
else if (this.velocity.x < 0)
|
||||
{
|
||||
this.velocity.x += this._drag;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.drag.y !== 0 && this.acceleration.y === 0)
|
||||
{
|
||||
this._drag = this.drag.y * this.game.time.physicsElapsed;
|
||||
|
||||
if (this.velocity.y > 0)
|
||||
{
|
||||
this.velocity.y -= this._drag;
|
||||
}
|
||||
else if (this.velocity.y < 0)
|
||||
{
|
||||
this.velocity.y += this._drag;
|
||||
}
|
||||
this.velocity.x = Math.cos(this.angle) * this.speed;
|
||||
this.velocity.y = Math.sin(this.angle) * this.speed;
|
||||
}
|
||||
|
||||
this.x += this.game.time.physicsElapsed * (this.velocity.x + this.motionVelocity.x / 2);
|
||||
|
@ -485,74 +471,22 @@ Phaser.Physics.Arcade.Body.prototype = {
|
|||
this.y += this.game.time.physicsElapsed * (this.velocity.y + this.motionVelocity.y / 2);
|
||||
this.velocity.y += this.motionVelocity.y;
|
||||
|
||||
|
||||
/*
|
||||
if (this.drag.x !== 0 && this.acceleration.x === 0)
|
||||
{
|
||||
this._drag = this.drag.x * this.game.time.physicsElapsed;
|
||||
|
||||
if (this.velocity.x - this._drag > 0)
|
||||
{
|
||||
this.velocity.x -= this._drag;
|
||||
this.x += this.game.time.physicsElapsed * (this.velocity.x + this.motionVelocity.x / 2);
|
||||
this.velocity.x += this.motionVelocity.x;
|
||||
}
|
||||
else if (this.velocity.x + this.drag.x < 0)
|
||||
{
|
||||
this.velocity.x += this._drag;
|
||||
this.x += this.game.time.physicsElapsed * (this.velocity.x + this.motionVelocity.x / 2);
|
||||
this.velocity.x += this.motionVelocity.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.velocity.x = 0;
|
||||
// this.preX = this.x;
|
||||
// this.motionVelocity.x = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.x += this.game.time.physicsElapsed * (this.velocity.x + this.motionVelocity.x / 2);
|
||||
this.velocity.x += this.motionVelocity.x;
|
||||
}
|
||||
|
||||
if (this.drag.y !== 0 && this.acceleration.y === 0)
|
||||
{
|
||||
this._drag = this.drag.y * this.game.time.physicsElapsed;
|
||||
|
||||
if (this.velocity.y - this._drag > 0)
|
||||
{
|
||||
this.velocity.y -= this._drag;
|
||||
this.y += this.game.time.physicsElapsed * (this.velocity.y + this.motionVelocity.y / 2);
|
||||
this.velocity.y += this.motionVelocity.y;
|
||||
}
|
||||
else if (this.velocity.y + this.drag.y < 0)
|
||||
{
|
||||
this.velocity.y += this._drag;
|
||||
this.y += this.game.time.physicsElapsed * (this.velocity.y + this.motionVelocity.y / 2);
|
||||
this.velocity.y += this.motionVelocity.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.velocity.y = 0;
|
||||
// this.preY = this.y;
|
||||
// this.motionVelocity.y = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.y += this.game.time.physicsElapsed * (this.velocity.y + this.motionVelocity.y / 2);
|
||||
this.velocity.y += this.motionVelocity.y;
|
||||
}
|
||||
*/
|
||||
|
||||
if (this.velocity.x > this.maxVelocity.x)
|
||||
{
|
||||
// this.velocity.x = this.maxVelocity.x;
|
||||
this.velocity.x = this.maxVelocity.x;
|
||||
}
|
||||
else if (this.velocity.x < -this.maxVelocity.x)
|
||||
{
|
||||
// this.velocity.x = -this.maxVelocity.x;
|
||||
this.velocity.x = -this.maxVelocity.x;
|
||||
}
|
||||
|
||||
if (this.velocity.y > this.maxVelocity.y)
|
||||
{
|
||||
this.velocity.y = this.maxVelocity.y;
|
||||
}
|
||||
else if (this.velocity.y < -this.maxVelocity.y)
|
||||
{
|
||||
this.velocity.y = -this.maxVelocity.y;
|
||||
}
|
||||
|
||||
if (this.collideWorldBounds)
|
||||
|
@ -606,7 +540,7 @@ Phaser.Physics.Arcade.Body.prototype = {
|
|||
|
||||
if (this.collideWorldBounds)
|
||||
{
|
||||
// this.checkWorldBounds();
|
||||
this.checkWorldBounds();
|
||||
}
|
||||
|
||||
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
|
||||
|
|
|
@ -260,7 +260,8 @@ Phaser.StageScaleMode.prototype = {
|
|||
this._width = this.width;
|
||||
this._height = this.height;
|
||||
|
||||
// console.log('startFullScreen', this._width, this._height);
|
||||
// This needs updating to match the final spec:
|
||||
// http://generatedcontent.org/post/70347573294/is-your-fullscreen-api-code-up-to-date-find-out-how-to
|
||||
|
||||
if (element['requestFullScreen'])
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue