class Talk( val speaker : Actor, val height : float, val seconds : double ) : ActionRole { var bubbleA : Actor = null var offsetX = 0 override fun createAction() : Action { bubbleA = speaker.createChild( "bubble" ).apply { ninePatchAppearance.size.x = actor.textAppearance.width() + 20 ninePatchAppearance.size.y = actor.textAppearance.height() + 30 zOrder = actor.zOrder - 0.1 color.alpha = 0.9 } offsetX = -actor.textAppearance.width()/4 return Delay( seconds ) then ( Fade( actor, 0.5, 0 ) and Fade( bubbleA, 0.5, 0) ) then ( Kill( bubbleA ) and Kill( actor ) ) } override fun tick() { super.tick() actor.direction.set( speaker.direction ) actor.direction.degrees -= 90 // Take into account that the ship points upwards bubbleA.direction.set( actor.direction ) actor.position.set( speaker.position ) actor.moveForwards( offsetX ) actor.moveSidewards( -height ) bubbleA.position.set( actor.position ) bubbleA.moveSidewards( 18 ) } static fun talk( speaker : Actor, message : String , seconds : double ) { val talkA = speaker.createChild( "talk" ) talkA.textAppearance.text = message talkA.role = Talk( speaker, 40, seconds ) } }