From 5af0631465205fe0c14bf28963d32d16021c4114 Mon Sep 17 00:00:00 2001 From: Viktor Lidholt Date: Fri, 16 Oct 2015 10:19:25 -0700 Subject: [PATCH] Adds teleporting methods for moving sprite kinematic physics bodies without assigning velocities --- skysprites/lib/src/node.dart | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/skysprites/lib/src/node.dart b/skysprites/lib/src/node.dart index e3151585a7b11..13b98427a8b87 100644 --- a/skysprites/lib/src/node.dart +++ b/skysprites/lib/src/node.dart @@ -148,6 +148,16 @@ class Node { invalidateTransformMatrix(); } + void teleportRotation(double rotation) { + assert(rotation != null); + if (_physicsBody != null && parent is PhysicsNode) { + _physicsBody._body.setTransform(_physicsBody._body.position, radians(rotation)); + _physicsBody._body.angularVelocity = 0.0; + _physicsBody._body.setType(box2d.BodyType.STATIC); + } + _setRotationFromPhysics(rotation); + } + /// The position of this node relative to its parent. /// /// myNode.position = new Point(42.0, 42.0); @@ -172,6 +182,23 @@ class Node { invalidateTransformMatrix(); } + void teleportPosition(Point position) { + assert(position != null); + if (_physicsBody != null && parent is PhysicsNode) { + PhysicsNode physicsNode = parent; + _physicsBody._body.setTransform( + new Vector2( + position.x / physicsNode.b2WorldToNodeConversionFactor, + position.y / physicsNode.b2WorldToNodeConversionFactor + ), + _physicsBody._body.getAngle() + ); + _physicsBody._body.linearVelocity = new Vector2.zero(); + _physicsBody._body.setType(box2d.BodyType.STATIC); + } + _setPositionFromPhysics(position); + } + /// The skew along the x-axis of this node in degrees. /// /// myNode.skewX = 45.0;