Skip to content

Commit

Permalink
update Sprite
Browse files Browse the repository at this point in the history
  • Loading branch information
Deficuet authored and Deficuet committed Jan 7, 2024
1 parent 36bd944 commit 2cc49af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/kotlin/io/github/deficuet/unitykt/classes/Sprite.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ interface Sprite: NamedObject {
val mRD: SpriteRenderData
val mPhysicsShape: Array<out Array<out Vector2>>

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?
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2cc49af

Please sign in to comment.