I have created raining animation using Sketch. The rain is then draw using this code with drawLine() with shift Offset. RaindropList is list of multiple generated raindrops with different starting coordinates.
Sketch(modifier = Modifier.fillMaxSize(),
speed = 1f, onDraw = { time ->
val advance = abs(time - lastTime)
raindropList.forEach { raindrop ->
drawRaindropLine(
raindrop = raindrop,
raindropSpeed = advance * 20000, // shift Offset
)
}
lastTime = time
}
)
Shift offset and drawLine() inside drawRaindropLine(). When raindrop is out off the screen coordinates are set to 0 again.
val shiftOffset = Offset(
x = 0f,
y = raindropSpeed
)
drawLine(
color = Color.White,
start = startOffset + shiftOffset,
end = endOffset + shiftOffset
)
My question is if this is the good approach to this kind of animation where there are multiple items on the screen which needs to be redrawn. I have mainly concerns about performance and I had to add check if time difference/advance is too large in some cases which is never good sign. The big advantage is that there is simple way how to change animation speed or stop it.
Thanks
