mirror of
https://github.com/cmclark00/mintris.git
synced 2025-05-18 08:25:21 +01:00
fix: prevent crash in game over animation by checking for zero blur radius
This commit is contained in:
parent
292ea656f8
commit
7dccad8d12
1 changed files with 30 additions and 20 deletions
|
@ -57,6 +57,15 @@ class GameView @JvmOverloads constructor(
|
|||
isAntiAlias = true
|
||||
}
|
||||
|
||||
private val borderGlowPaint = Paint().apply {
|
||||
color = Color.WHITE
|
||||
alpha = 60
|
||||
isAntiAlias = true
|
||||
style = Paint.Style.STROKE
|
||||
strokeWidth = 2f
|
||||
maskFilter = BlurMaskFilter(8f, BlurMaskFilter.Blur.OUTER)
|
||||
}
|
||||
|
||||
private val ghostBlockPaint = Paint().apply {
|
||||
color = Color.WHITE
|
||||
alpha = 80 // 30% opacity
|
||||
|
@ -89,15 +98,6 @@ class GameView @JvmOverloads constructor(
|
|||
maskFilter = BlurMaskFilter(12f, BlurMaskFilter.Blur.OUTER)
|
||||
}
|
||||
|
||||
private val borderGlowPaint = Paint().apply {
|
||||
color = Color.WHITE
|
||||
alpha = 60
|
||||
isAntiAlias = true
|
||||
style = Paint.Style.STROKE
|
||||
strokeWidth = 2f
|
||||
maskFilter = BlurMaskFilter(8f, BlurMaskFilter.Blur.OUTER)
|
||||
}
|
||||
|
||||
// Add a new paint for the pulse effect
|
||||
private val pulsePaint = Paint().apply {
|
||||
color = Color.CYAN
|
||||
|
@ -410,12 +410,6 @@ class GameView @JvmOverloads constructor(
|
|||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
// Skip drawing if paused or game over - faster return
|
||||
if (isPaused || gameBoard.isGameOver) {
|
||||
super.onDraw(canvas)
|
||||
return
|
||||
}
|
||||
|
||||
// Set hardware layer type during draw for better performance
|
||||
val wasHardwareAccelerated = isHardwareAccelerated
|
||||
if (!wasHardwareAccelerated) {
|
||||
|
@ -447,12 +441,28 @@ class GameView @JvmOverloads constructor(
|
|||
if (isGameOverAnimating) {
|
||||
val gameOverPaint = Paint().apply {
|
||||
color = Color.WHITE
|
||||
alpha = (128 * gameOverAlpha).toInt()
|
||||
alpha = (200 * gameOverAlpha).toInt() // Increased from 128 to 200
|
||||
isAntiAlias = true
|
||||
style = Paint.Style.FILL
|
||||
maskFilter = BlurMaskFilter(48f * gameOverAlpha, BlurMaskFilter.Blur.OUTER)
|
||||
// Only apply blur if alpha is greater than 0
|
||||
if (gameOverAlpha > 0) {
|
||||
maskFilter = BlurMaskFilter(64f * gameOverAlpha, BlurMaskFilter.Blur.OUTER) // Increased from 48f to 64f
|
||||
}
|
||||
}
|
||||
canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), gameOverPaint)
|
||||
|
||||
// Add a second layer for more intensity
|
||||
val gameOverPaint2 = Paint().apply {
|
||||
color = Color.WHITE
|
||||
alpha = (100 * gameOverAlpha).toInt()
|
||||
isAntiAlias = true
|
||||
style = Paint.Style.FILL
|
||||
// Only apply blur if alpha is greater than 0
|
||||
if (gameOverAlpha > 0) {
|
||||
maskFilter = BlurMaskFilter(32f * gameOverAlpha, BlurMaskFilter.Blur.OUTER)
|
||||
}
|
||||
}
|
||||
canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), gameOverPaint2)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1163,8 +1173,8 @@ class GameView @JvmOverloads constructor(
|
|||
gameHaptics?.vibrateForGameOver()
|
||||
|
||||
// Create new game over animation
|
||||
gameOverAnimator = ValueAnimator.ofFloat(0f, 1f, 0.7f).apply {
|
||||
duration = 1500L // 1.5 seconds total
|
||||
gameOverAnimator = ValueAnimator.ofFloat(0f, 1f, 0.8f).apply {
|
||||
duration = 1000L // 1 second total
|
||||
interpolator = LinearInterpolator()
|
||||
|
||||
addUpdateListener { animation ->
|
||||
|
@ -1177,7 +1187,7 @@ class GameView @JvmOverloads constructor(
|
|||
addListener(object : android.animation.AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: android.animation.Animator) {
|
||||
isGameOverAnimating = false
|
||||
gameOverAlpha = 0.7f // Keep at 70% opacity
|
||||
gameOverAlpha = 0.8f // Keep at 80% opacity
|
||||
invalidate()
|
||||
Log.d(TAG, "Game over animation ended")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue