I'm working on a video game that redraws every 1/60 of a second using Kotlin and TornadoFX/JavaFX. Currently, my program redraws by setting the background to white and drawing over it. However, I would prefer something that is a bit cleaner. This is how I'm drawing it currently:
private fun drawShapes(gc: GraphicsContext) {
gc.fill = c(255, 255, 255)
gc.fillRect(0.0, 0.0, 700.0, 700.0) //Game is 700x700
gc.fill = c(94, 132, 233)
walls.forEach { gc.fillRect(it.x.toDouble(), it.y.toDouble(), it.w.toDouble(), it.h.toDouble()) }
gc.fill = c(255, 239, 20)
coins.filter { !it.collected }.forEach { gc.fillRect(it.x.toDouble(), it.y.toDouble(), it.w.toDouble(), it.h.toDouble()) }
//Cut off here because following is more of same
}
fixedRateTimer(period = 16, initialDelay = 500) { drawShapes(graphicsContext2D) }
Is there any way to simply wipe it clean instead of layering a lot on top of each other? I've tried searching the internet for it, but I couldn't find anything.