diff --git a/Sources/iron/object/MeshObject.hx b/Sources/iron/object/MeshObject.hx index 7c6b928b..089144fa 100644 --- a/Sources/iron/object/MeshObject.hx +++ b/Sources/iron/object/MeshObject.hx @@ -25,7 +25,8 @@ class MeshObject extends Object { public var cameraDistance: Float; public var screenSize = 0.0; public var frustumCulling = true; - public var tilesheet: Tilesheet = null; + public var activeTilesheet: Tilesheet = null; + public var tilesheets: Array = null; public var skip_context: String = null; // Do not draw this context public var force_context: String = null; // Draw only this context static var lastPipeline: PipelineState = null; @@ -79,7 +80,8 @@ class MeshObject extends Object { particleSystems = null; } #end - if (tilesheet != null) tilesheet.remove(); + if (activeTilesheet != null) activeTilesheet.remove(); + if (tilesheets != null) for (ts in tilesheets) { ts.remove(); } if (Scene.active != null) Scene.active.meshes.remove(this); data.refcount--; super.remove(); @@ -115,7 +117,29 @@ class MeshObject extends Object { #end public function setupTilesheet(sceneName: String, tilesheet_ref: String, tilesheet_action_ref: String) { - tilesheet = new Tilesheet(sceneName, tilesheet_ref, tilesheet_action_ref); + activeTilesheet = new Tilesheet(sceneName, tilesheet_ref, tilesheet_action_ref); + if(tilesheets == null) tilesheets = new Array(); + tilesheets.push(activeTilesheet); + } + + public function setActiveTilesheet(sceneName: String, tilesheet_ref: String, tilesheet_action_ref: String) { + var set = false; + // Check if tilesheet already created + if (tilesheets != null) { + for (ts in tilesheets) { + if (ts.raw.name == tilesheet_ref) { + activeTilesheet = ts; + activeTilesheet.play(tilesheet_action_ref); + set = true; + break; + } + } + } + // If not already created + if (!set) { + setupTilesheet(sceneName, tilesheet_ref, tilesheet_action_ref); + } + } inline function isLodMaterial(): Bool { diff --git a/Sources/iron/object/ParticleSystem.hx b/Sources/iron/object/ParticleSystem.hx index c49f97d2..16bd1a11 100644 --- a/Sources/iron/object/ParticleSystem.hx +++ b/Sources/iron/object/ParticleSystem.hx @@ -101,10 +101,10 @@ class ParticleSystem { dimx = object.transform.dim.x; dimy = object.transform.dim.y; - if (object.tilesheet != null) { - tilesx = object.tilesheet.raw.tilesx; - tilesy = object.tilesheet.raw.tilesy; - tilesFramerate = object.tilesheet.raw.framerate; + if (object.activeTilesheet != null) { + tilesx = object.activeTilesheet.raw.tilesx; + tilesy = object.activeTilesheet.raw.tilesy; + tilesFramerate = object.activeTilesheet.raw.framerate; } // Animate diff --git a/Sources/iron/object/Tilesheet.hx b/Sources/iron/object/Tilesheet.hx index 653cd599..210f68aa 100644 --- a/Sources/iron/object/Tilesheet.hx +++ b/Sources/iron/object/Tilesheet.hx @@ -59,6 +59,23 @@ class Tilesheet { Scene.active.tilesheets.remove(this); } + /** + * Set the frame of the current active tilesheet action. Automatically un-pauses action. + * @param frame Frame offset with 0 as the first frame of the active action. + **/ + public function setFrameOffset(frame: Int) { + setFrame(action.start + frame); + paused = false; + } + + /** + * Returns the current frame. + * @return Frame offset with 0 as the first frame of the active action. + */ + public function getFrameOffset(): Int { + return frame - action.start; + } + function update() { if (!ready || paused || action.start >= action.end) return; diff --git a/Sources/iron/object/Uniforms.hx b/Sources/iron/object/Uniforms.hx index a24e268d..5eabdeba 100644 --- a/Sources/iron/object/Uniforms.hx +++ b/Sources/iron/object/Uniforms.hx @@ -1044,10 +1044,15 @@ class Uniforms { var vy: Null = null; switch (c.link) { case "_tilesheetOffset": { - var ts = cast(object, MeshObject).tilesheet; + var ts = cast(object, MeshObject).activeTilesheet; vx = ts.tileX; vy = ts.tileY; } + case "_tilesheetTiles": { + var ts = cast(object, MeshObject).activeTilesheet; + vx = ts.raw.tilesx; + vy = ts.raw.tilesy; + } #if arm_morph_target case "_morphScaleOffset": { var mt = cast(object, MeshObject).morphTarget;