Skip to content

Commit 87ca500

Browse files
committed
feat: new API for extracting Image from a channel given the frame index
1 parent e539eba commit 87ca500

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

fxgl-core/src/main/kotlin/com/almasb/fxgl/texture/AnimationChannel.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ class AnimationChannel(val image: Image,
9999
fun getFrameWidth(frame: Int) = getFrameData(frame).width
100100
fun getFrameHeight(frame: Int) = getFrameData(frame).height
101101

102+
/**
103+
* @return a computed image for a given [frameIndex]
104+
*/
105+
fun getFrameImage(frameIndex: Int): Image {
106+
val frameData = getFrameData(frameIndex)
107+
108+
return Texture(image).subTexture(frameData.viewport).image
109+
}
110+
102111
/**
103112
* Returns next frame index or 0 if [frame] is last.
104113
*/

0 commit comments

Comments
 (0)