korlibs / korge

KorGE Game Engine. Multiplatform Kotlin Game Engine
https://korge.org/
Other
2.5k stars 123 forks source link

Flipping BmpSlice #376

Open BioRyajenka opened 3 years ago

BioRyajenka commented 3 years ago

Hi, is there a way to flip BmpSlice?

I know I can extract it to bmp, then flip, and then get the slice:

val flipped = bmpSlice.extract().flipX().slice()

But I afraid it will affect performance in a bad way (because a new bmp created each time; and too many bmps are bad for performance). So is there a better way?

Also, is my suggestion is true: "using less but larger BMPs are better for performance"?

soywiz commented 3 years ago

I believe you can do something like (untested):

val slice: BmpSlice
val sliceFlippedX: BmpSlice = BmpSlice(slice.bmpBase, RectangleInt(sice.bounds.right, sice.bounds.top, -sice.bounds.width, -sice.bounds.height))
BioRyajenka commented 3 years ago

Wonderful, thanks!

soywiz commented 3 years ago

Nice. Glad it helped. Let me keep this issue open. Maybe we can provide a method like .flipX().flipY() or xFlipped yFlipped doing exactly that 👍

BioRyajenka commented 3 years ago

Just for info: actually your suggestion didn't help. It seems like provided code just shifts bmp slice "window" left up on the bmp.