Remember last position in sprite physics

This commit is contained in:
Viktor Lidholt
2015-10-15 14:43:48 -07:00
parent f164289203
commit 46415fa02b
2 changed files with 9 additions and 0 deletions

View File

@@ -40,6 +40,9 @@ class PhysicsBody {
this.active = active;
}
Vector2 _lastPosition;
double _lastRotation;
Object tag;
final PhysicsShape shape;

View File

@@ -113,6 +113,9 @@ class PhysicsNode extends Node {
}
void _updatePosition(PhysicsBody body, Point position) {
if (body._lastPosition == null)
body._lastPosition = body._body.position;
Vector2 newPos = new Vector2(
position.x / b2WorldToNodeConversionFactor,
position.y / b2WorldToNodeConversionFactor
@@ -123,6 +126,9 @@ class PhysicsNode extends Node {
}
void _updateRotation(PhysicsBody body, double rotation) {
if (body._lastRotation == null)
body._lastRotation = body._body.getAngle();
Vector2 pos = body._body.position;
double newAngle = radians(rotation);
body._body.setTransform(pos, newAngle);