From 5348f74c3d83b00328c0a934bfa66ae04fe3a10a Mon Sep 17 00:00:00 2001 From: js Date: Thu, 11 May 2023 19:19:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=A0=B4=E5=9D=8F?= =?UTF-8?q?=E5=8E=9F=E5=9B=BE=E7=9A=84=E8=A1=8C=E4=B8=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../element/animation/DyingAnimation.kt | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/net/imshit/aircraftwar/element/animation/DyingAnimation.kt b/app/src/main/java/net/imshit/aircraftwar/element/animation/DyingAnimation.kt index 6d9d6ba..bed690f 100644 --- a/app/src/main/java/net/imshit/aircraftwar/element/animation/DyingAnimation.kt +++ b/app/src/main/java/net/imshit/aircraftwar/element/animation/DyingAnimation.kt @@ -11,39 +11,38 @@ class DyingAnimation( game = aircraft.game, initialX = aircraft.x, initialY = aircraft.y, speedX = 0f, speedY = 0f ) { - val alpha = 0x80 - val liveMs = 500 - val flashMs = 100 + val ALPHA = 0x80 + val LIVE_MS = 500 + val FLASH_MS = 100 fun makeLightImage(image: Bitmap): Bitmap { - return image.run { - IntArray(width * height).also { - getPixels(it, 0, width, 0, 0, width, height) - }.map { color -> - Color.argb( - this@DyingAnimation.alpha, - Color.red(color), - Color.green(color), - Color.blue(color) - ) - }.toIntArray().run { - Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) - .also { setPixels(this, 0, width, 0, 0, width, height) } - } - } + val width = image.width + val height = image.height + val pixels = + IntArray(width * height).also { image.getPixels(it, 0, width, 0, 0, width, height) } + val lightPixels = pixels.map { color -> + Color.argb( + Color.TRANSPARENT, + Color.red(color) * this.ALPHA, + Color.green(color) * this.ALPHA, + Color.blue(color) * this.ALPHA + ) + }.toIntArray() + return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) + .apply { setPixels(lightPixels, 0, width, 0, 0, width, height) } } val baseImage = aircraft.image val lightImage = makeLightImage(this.baseImage) override var image = this.baseImage - var life = this.liveMs + var life = this.LIVE_MS override fun forward(timeMs: Int) { this.life -= timeMs if (this.life <= 0) { this.vanish() } - this.image = if ((this.life / flashMs) % 2 == 1) { + this.image = if ((this.life / FLASH_MS) % 2 == 1) { this.baseImage } else { this.lightImage