Commit 46415fa0 authored by Viktor Lidholt's avatar Viktor Lidholt

Remember last position in sprite physics

parent f1642892
......@@ -40,6 +40,9 @@ class PhysicsBody {
this.active = active;
}
Vector2 _lastPosition;
double _lastRotation;
Object tag;
final PhysicsShape shape;
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment