trying to smothen the differences between server and client

This commit is contained in:
Jeena 2014-02-18 13:15:19 +01:00
parent 47bb5ef147
commit cda69dcfd4

View file

@ -64,7 +64,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
if(updateData[gameObject.uid]) {
var update = updateData[gameObject.uid];
body.SetAwake(true);
body.SetPosition(update.p);
body.SetPosition(this.centerBetween(update.p, body.GetPosition()));
body.SetAngle(update.a);
body.SetLinearVelocity(update.lv);
body.SetAngularVelocity(update.av);
@ -80,6 +80,24 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
}
GameController.prototype.centerBetween = function(n, o) {
var x, y;
if(n.x > o.x) {
x = o.x + (n.x - o.x) / 2;
} else {
x = o.x - (o.x - n.x) / 2;
}
if(n.y > o.y) {
y = o.y + (n.y - o.y) / 2;
} else {
y = o.y - (o.y - n.y) / 2;
}
return {x:x, y:y};
};
GameController.prototype.onJoinMe = function (playerId) {
this.me = this.players[playerId];
this.me.setPlayerController(new PlayerController(this.me));