/** * An elastic line between the GraphicalMouse and the item being dragged. * Used on the Doll House scenes to pick up and move [DollPart]s, and other [Draggable] items. */ class Elastic : AbstractRole() { var dragging : Draggable = null // Private set by join(...) var mouseJoint: TickleMouseJoint = null // Temporary vector to hold the end positions of the elastic line. val tmp = Vector2() override fun begin() { super.begin() actor.hide() } override fun tick() { if ( dragging != null ) { val mainView = DollsHouseDirector.instance.mainView mainView.getMousePositionWorld( tmp ) mouseJoint.target = tmp actor.position.set( tmp ) mouseJoint.getAnchorB(tmp) actor.ninePatchAppearance.lineTo(tmp) } } fun join( role : Draggable, hand : GraphicalMouse, position : Vector2 ) { //actor.show() actor.event( "default" ) val world = DollsHouseDirector.instance.mainView.stage.world role.actor.body.setAwake( true ) val maxForce = 4 * role.mass() mouseJoint = TickleMouseJoint( hand.actor, role.actor, position, maxForce ) dragging = role } fun unjoin() { if (dragging != null) { actor.hide() dragging = null mouseJoint.destroy() mouseJoint = null } } }