diff --git a/scripts/graphics.cm b/scripts/graphics.cm index acab9a2f..45014b12 100644 --- a/scripts/graphics.cm +++ b/scripts/graphics.cm @@ -305,6 +305,12 @@ graphics.texture = function texture(path) { var animName = parts[1] 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]) { var ipath = res.find_image(id) if (!ipath) @@ -316,8 +322,24 @@ graphics.texture = function texture(path) { var cached = cache[id] - // No further path specifiers - return the whole thing - if (!animName) return cached + // No further path specifiers and no frame index - return the whole thing + 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 instanceof graphics.Image) { @@ -325,8 +347,8 @@ graphics.texture = function texture(path) { // For single images, any frame index just returns the image return cached } - // animName without frameIndex for single image - return the image - return cached + // animName without frameIndex for single image - return as single-frame array + return [cached] } // If cached is a single animation (has .frames property)