class BounceFactoryOptimised : ActionRole { @Attribute var initialVelocity = Vector2() override fun createAction() : Action { actor.hide() return ( Delay( 0.01 ) thenOnce this:>create ).forever() } fun create() { val child = actor.createChild( "child" ) child.scaleXY = actor.scaleXY (child.role as NeighbourhoodBounce).apply { radius *= actor.scaleXY velocity.set( initialVelocity ) } } }