constrain method
- @override
Called after update is complete, if the constraint has been added to a Node. Override this method to modify the node's property according to the constraint.
Implementation
@override
void constrain(Node node, double dt) {
Offset targetPosition;
if (targetNode.spriteBox != node.spriteBox || node.parent == null) {
// The target node is in another sprite box or has been removed
return;
}
if (targetNode.parent == node.parent) {
targetPosition = targetNode.position;
} else {
targetPosition = node.parent.convertPointFromNode(Offset.zero, targetNode);
}
if (offset != null)
targetPosition += offset;
if (dampening == null)
node.position = targetPosition;
else
node.position = GameMath.filterPoint(node.position, targetPosition, dampening);
}