bug fix: graphics now correctly returns frames of single anims
This commit is contained in:
@@ -305,6 +305,12 @@ graphics.texture = function texture(path) {
|
|||||||
var animName = parts[1]
|
var animName = parts[1]
|
||||||
var frameIndex = parts[2]
|
var frameIndex = parts[2]
|
||||||
|
|
||||||
|
// Handle the case where animName is actually a frame index (e.g., "gears:0")
|
||||||
|
if (animName != null && frameIndex == null && !isNaN(parseInt(animName))) {
|
||||||
|
frameIndex = parseInt(animName)
|
||||||
|
animName = null
|
||||||
|
}
|
||||||
|
|
||||||
if (!cache[id]) {
|
if (!cache[id]) {
|
||||||
var ipath = res.find_image(id)
|
var ipath = res.find_image(id)
|
||||||
if (!ipath)
|
if (!ipath)
|
||||||
@@ -316,8 +322,24 @@ graphics.texture = function texture(path) {
|
|||||||
|
|
||||||
var cached = cache[id]
|
var cached = cache[id]
|
||||||
|
|
||||||
// No further path specifiers - return the whole thing
|
// No further path specifiers and no frame index - return the whole thing
|
||||||
if (!animName) return cached
|
if (!animName && frameIndex == null) return cached
|
||||||
|
|
||||||
|
// Handle frame index without animation name (e.g., "gears:0")
|
||||||
|
if (!animName && frameIndex != null) {
|
||||||
|
// If cached is a single animation (has .frames property)
|
||||||
|
if (cached.frames && Array.isArray(cached.frames)) {
|
||||||
|
var idx = parseInt(frameIndex)
|
||||||
|
if (isNaN(idx)) return cached
|
||||||
|
// Wrap the index
|
||||||
|
idx = idx % cached.frames.length
|
||||||
|
return cached.frames[idx].image
|
||||||
|
}
|
||||||
|
// If cached is a single Image, any frame index just returns the image
|
||||||
|
if (cached instanceof graphics.Image) {
|
||||||
|
return cached
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If cached is a single Image, treat it as a single-frame animation
|
// If cached is a single Image, treat it as a single-frame animation
|
||||||
if (cached instanceof graphics.Image) {
|
if (cached instanceof graphics.Image) {
|
||||||
@@ -325,8 +347,8 @@ graphics.texture = function texture(path) {
|
|||||||
// For single images, any frame index just returns the image
|
// For single images, any frame index just returns the image
|
||||||
return cached
|
return cached
|
||||||
}
|
}
|
||||||
// animName without frameIndex for single image - return the image
|
// animName without frameIndex for single image - return as single-frame array
|
||||||
return cached
|
return [cached]
|
||||||
}
|
}
|
||||||
|
|
||||||
// If cached is a single animation (has .frames property)
|
// If cached is a single animation (has .frames property)
|
||||||
|
|||||||
Reference in New Issue
Block a user