diff --git a/src/main/kotlin/io/github/deficuet/unitykt/classes/Sprite.kt b/src/main/kotlin/io/github/deficuet/unitykt/classes/Sprite.kt index 254f45e4..b8377604 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/classes/Sprite.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/classes/Sprite.kt @@ -21,10 +21,12 @@ interface Sprite: NamedObject { val mRD: SpriteRenderData val mPhysicsShape: Array> + fun getTexture2D(): Texture2D? + /** - * Has the same orientation as the parent [Texture2D] + * @return The cropped [BufferedImage] which has the same orientation as the parent [Texture2D]. * - * i.e. usually up-side-down + * i.e. usually up-side-down. */ fun getImage(): BufferedImage? } diff --git a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/SpriteImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/SpriteImpl.kt index 599ae322..8a9067b2 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/SpriteImpl.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/SpriteImpl.kt @@ -108,12 +108,22 @@ internal class SpriteImpl( } else emptyArray() } + override fun getTexture2D(): Texture2D? { + val spriteAtlas = mSpriteAtlas?.safeGetObj() + return if (spriteAtlas != null) { + spriteAtlas.mRenderDataMap[mRenderDataKey]?.texture?.safeGetObj() + } else { + mRD.texture.safeGetObj() + } + } + override fun getImage(): BufferedImage? { val spriteAtlas = mSpriteAtlas?.safeGetObj() if (spriteAtlas != null) { val spriteAtlasData = spriteAtlas.mRenderDataMap[mRenderDataKey] val tex = spriteAtlasData?.texture?.safeGetObj() if (tex != null) { + println(tex.mPathID) return cutImage( tex, spriteAtlasData.textureRect, //spriteAtlasData.textureRectOffset, spriteAtlasData.downScaleMultiplier, spriteAtlasData.settingsRaw