{"id":16728777,"url":"https://github.com/enoughtea/plainspritesheetanimation","last_synced_at":"2025-09-08T23:32:41.697Z","repository":{"id":29905069,"uuid":"33450788","full_name":"EnoughTea/plainspritesheetanimation","owner":"EnoughTea","description":"Plain sprite sheet animation library is a barebone library for a sprite sheet 2D animation support. It manages all information needed to draw a frame to screen; how exactly it is drawn is up to user.","archived":false,"fork":false,"pushed_at":"2017-09-25T09:59:18.000Z","size":73,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-08T23:32:07.288Z","etag":null,"topics":["animation-sequence","c-sharp","texturepacker"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EnoughTea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-05T18:35:27.000Z","updated_at":"2017-09-25T09:58:41.000Z","dependencies_parsed_at":"2022-09-05T01:01:11.338Z","dependency_job_id":null,"html_url":"https://github.com/EnoughTea/plainspritesheetanimation","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/EnoughTea/plainspritesheetanimation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EnoughTea%2Fplainspritesheetanimation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EnoughTea%2Fplainspritesheetanimation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EnoughTea%2Fplainspritesheetanimation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EnoughTea%2Fplainspritesheetanimation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EnoughTea","download_url":"https://codeload.github.com/EnoughTea/plainspritesheetanimation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EnoughTea%2Fplainspritesheetanimation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274231182,"owners_count":25245675,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-08T02:00:09.813Z","response_time":121,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["animation-sequence","c-sharp","texturepacker"],"created_at":"2024-10-12T23:11:41.413Z","updated_at":"2025-09-08T23:32:41.670Z","avatar_url":"https://github.com/EnoughTea.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# Plain sprite-sheet animation library\n\nPlain sprite sheet animation library is a barebones library for a sprite sheet 2D animation support.\nIt manages all information needed to draw a frame to screen; how exactly it is drawn is up to user.\n\nIt is a personal library and it is not supposed to be a complex framework, but perhaps someone could find it useful.\n\n\n## Well, what is it?\n\nAnimation is represented as a sequence of frames. These could be created manually or loaded from [TexturePacker](https://www.codeandweb.com/texturepacker).\nThen you can set some properties defining how resulting sequence should be played. Call sequence update method in your update logic, draw its current frame if sequence is visible, and that's it.\n  * Plain and simple to use and extend.\n  * Supports [TexturePacker](https://www.codeandweb.com/texturepacker)'s generic XML format.\n  * Animation sequences are serializable through DataContractSerializer.\n\n\n### Creating animation sequences with TexturePacker's generic XML texture atlas description\n\nI like TexturePacker, so I will show it first. Just for the reference, TexturePacker's generic XML file looks like this:\n\n\t\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\t\u003c!-- Created with TexturePacker http://texturepacker.com--\u003e\n\t\u003c!-- $TexturePacker:SmartUpdate:78d3aff951abb5c82993a205c536379f$ --\u003e\n\t\u003c!--Format:\n\tn  =\u003e name of the sprite\n\tx  =\u003e sprite x pos in texture\n\ty  =\u003e sprite y pos in texture\n\tw  =\u003e sprite width (may be trimmed)\n\th  =\u003e sprite height (may be trimmed)\n\toX =\u003e sprite's x-corner offset (only available if trimmed)\n\toY =\u003e sprite's y-corner offset (only available if trimmed)\n\toW =\u003e sprite's original width (only available if trimmed)\n\toH =\u003e sprite's original height (only available if trimmed)\n\tr =\u003e 'y' only set if sprite is rotated\n\t--\u003e\n\t\u003cTextureAtlas imagePath=\"whole texture atlas.png\" width=\"1024\" height=\"2048\"\u003e\n\t\t\u003csprite n=\"walking 1.png\" x=\"0\" y=\"0\" w=\"32\" h=\"48\"/\u003e\n\t\t\u003csprite n=\"walking 2.png\" x=\"32\" y=\"0\" w=\"32\" h=\"48\"/\u003e\n\t\t\u003csprite n=\"walking 3.png\" x=\"64\" y=\"0\" w=\"32\" h=\"48\"/\u003e\n\t\t\u003csprite n=\"standing.png\" x=\"96\" y=\"0\" w=\"59\" h=\"83\"/\u003e\n\t\t...\n\t\u003c/TextureAtlas\u003e\n\nGiven this file, animation sequence could be created like this:\n\n\tusing (var atlasFileStream = File.OpenRead(atlasXmlFile)) {\n\t\tvar atlasData = TexturePackerAtlas.Load(atlasFileStream);\n\t\t// Now that TP's data is loaded, you can do whatever with it. Lets create sequences from it:\n\t\tvar animationSequences = atlasData.CreateAnimationSequences().ToList();\n\n\t\t// 'animationSequences' will contain two sequences: 1) \"walking\" with 3 frames; 2) \"standing\" with 1 frame.\n\t\tvar walking = animationSequences.FindSequenceByName(\"walking\");\n\t\tvar standing = animationSequences.FindSequenceByName(\"standing\");\n\t\t\t\n\t\t// Amount of time each frame is shown equals to 0 right now, since these are out of TexturePacker's scope.\n\t\t// It possible to set duration for entire sequence:\n\t\twalking.SetDuration(1f);\n\t\t// 'walking' consists of 3 frames with 0 second durations, this new duration will be distributed evenly.\n\t\t// Each frame's new duration would be 1/3.\n\t\t// By the way, if frame durations would have been set to something other than 0,\n\t\t// they would be scaled to new duration, keeping timing ratio between old and new durations.\n\n\t\t// Lets run 'walking' sequence in a loop:\n\t\twalking.AnimationType = AnimationType.Looping;\n\n\t\t// And 'standing' needs its only frame to be shown continously:\n\t\tstanding.AnimationType = OnceHoldLast;\n\n\t\t// I want 'standing' sequence to start when 'walking' one stops:\n\t\twalking.Stopped += (sequence, _) =\u003e standing.Start();\n\t\t// 'Stopped' event will occur when sequence is stopped. It can happen either when its time is up, \n\t\t// or when its 'Animating' property is changed by Stop() call or direct change by user.\n\t\t// 'Started' event works in similar way.\n\t}\n\n\n### Creating animation sequences through code:\n\nSame sequences as in example above can be created through code.\n\n\tstring walkingName = \"walking\";\n\tvar walkingFrames = new List\u003cAnimationFrame\u003e {\n\t\tnew AnimationFrame(new TextureRegion(0, 0, 32, 48), 1/3f),\n\t\tnew AnimationFrame(new TextureRegion(32, 0, 32, 48), 1/3f),\n\t\tnew AnimationFrame(new TextureRegion(64, 0, 32, 48), 1/3f),\n\t};\n\n\tvar walking = new AnimationSequence(walkingName, walkingFrames);\n\tvar standing = new AnimationSequence(\"standing\",\n\t\tnew[] { new AnimationFrame(new TextureRegion(96, 0, 59, 83), 0) });\n\n\n### One last thing\n\nAnimations need to know how much time has passed, so they need to be updated somewhere:\n\n\tprivate void YourLogicUpdate(float deltaTimeBetweenUpdatesInSeconds) {\n\t\t...\n\t\tanimationSequences.Update(deltaTimeBetweenUpdatesInSeconds);\n\t}\n\nThere is no built-in renderer, so you will need to have your own. Then rendering logic could look like this:\n\n\tprivate void YourDraw() {\n\t\tvar sequencesWhichNeedsDrawing = yourAnimationSequences.GetVisibleSequences();\n\t\tforeach (var sequence in sequencesWhichNeedsDrawing) {\n\t\t\tvar texture = YourTextureManager.GetTexture(sequence.TextureId);\n\t\t\tvar frameToDraw = sequence.CurrentFrame;\n\t\t\tvar textureSourceTexels = frameToDraw.Source;\n\t\t\tvar frameDrawOffset = frameToDraw.Origin;\n\t\t\tvar screenPosition = yourObjectPosition + frameDrawOffset;\n\t\t\tyourSpriteBatch.Draw(texture, screenPosition, textureSourceTexels, Color.White);\n\t\t}\n\t}\n\n\n### Unit tests NuGet references\n\nYou may notice that NuGet packages are not in the repository, so do not forget to set up package restoration in Visual Studio:\n\nTools menu → Options → Package Manager → General → \"Allow NuGet to download missing packages during build\" should be selected. \n\nIf you have a build server then it needs to be setup with an environment variable 'EnableNuGetPackageRestore' set to true.\n\nIf you do not use Visual Studio, then I guess that you already know how to restore packages from console.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenoughtea%2Fplainspritesheetanimation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenoughtea%2Fplainspritesheetanimation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenoughtea%2Fplainspritesheetanimation/lists"}