class Speech : ActionRole { val offset = Vector2( 0, 30 ) val textOffset = Vector2( 0, 110 ) var textA : Actor fun speak( parent : Role, text : String, seconds : double, color : Color ) { textA = actor.createChild( "text" ) textA.textAppearance.text = text textA.role = ActionRole( Follow( textA.position, parent.actor.position, textOffset ) ) actor.resize( textA.width() + 60, textA.height() + 100 ) offset.x = 80 - actor.width() / 2 textOffset.x = offset.x actor.scaleXY = 0.1 actor.color = color.copy() textA.color.alpha = 0 replaceAction( ( Follow( actor.position, parent.actor.position, offset ).forSeconds( seconds ) and ( ScaleTo( actor, 0.2, 1, Eases.easeIn ) then Fade( textA.color, 0.2, 1 ) ) and ( Delay( seconds-1 ) then (Fade(actor.color, 1, 0) and Fade(textA.color, 1, 0) ) ) ) then Kill( actor ) ) } // Removes the speech bubble immediately fun stop() { actor.die() } override fun end() { if ( textA != null ) { textA.die() textA = null } } }