I need a rectangle that needs to be initialized on call.
Here is my code;
class EpheButton private constructor(
private val text: String,
private val x: Float,
private val y: Float,
private val projectionMatrix: Matrix4) : Disposable {
private val spriteBatch: SpriteBatch = SpriteBatch()
private val bitmapFont: BitmapFont = BitmapFont()
private val shapeRenderer: ShapeRenderer = ShapeRenderer()
private val textWidth: Float
private val textHeight: Float
private val rectangle :Rectangle by lazy { Rectangle(x, y, textWidth, textHeight) }
init {
bitmapFont.data.setScale(2f)
bitmapFont.region.texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
bitmapFont.color = Color.BLUE
val layout = GlyphLayout()
layout.setText(bitmapFont, text)
textWidth = layout.width
textHeight = layout.height
}
I get errors for the line private val rectangle :Rectangle by lazy { Rectangle(x, y, textWidth, textHeight) }
which says that;
Variable 'textWidth' must be initialized Variable 'textHeight' must be initialized
But I am already initializing them on the init{}
code block.
What am I doing wrong?