Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Reworked tilesheets to implement support for Sparrow atlases. #182

Conversation

EliteMasterEric
Copy link

@EliteMasterEric EliteMasterEric commented Jan 2, 2023

The current implementation of Tilesheets in Armory is very limited. It only provides support for grids of square sprites, and playing a range of frames from the grid in order. This is highly inefficient, as it does not allow the spritesheet to be optimized or frames to be reused.

This pull request implements engine support for the Sparrow sprite format, which associates an XML file with the spritesheet, which looks like so:

<TextureAtlas imagePath="atlas.png">
 <SubTexture name="idle001" x="0" y="0" width="30" height="30"/>;
 <SubTexture name="idle002" x="30" y="0" width="65" height="78"/>;
 <SubTexture name="walk001" x="30" y="80" width="65" height="78"/>;
 <SubTexture name="walk002" x="30" y="80" width="65" height="78"/>;
 ...
</TextureAtlas>;

These spritesheets can be generated by programs such as TexturePacker or Adobe Animate.

Developers can then specify frames by prefix, for example the Walk animation will use the frames with the name walk, in order.

Care was taken to ensure relatively few breaking changes were made to the Tilesheet class, but a more optimal code structure may require a rework to Tilesheet (such as making tilesheet a parent to GridTilesheet and SparrowTilesheet subclasses).

There is also room to add additional file formats as users request them.

TODO

  • Fix implementation of frameX, frameY, frameWidth, and frameHeight. Parts of the spritesheet outside the current frame should be hidden. I couldn't figure out how to do this, changes need to be made to the shader code somewhere.
  • Implement flipX, flipY, and rotate attributes. These indicate that the frame should be rendered flipped horizontally, flipped vertically, or rotated by 90 degrees, respectively. These attributes are used to further optimize a spritesheet by minimizing transparent space.

Note

This pull request is associated with armory3d/armory#2745, and will not function as intended without it.

@luboslenco
Copy link
Member

Super cool, thanks! It would be nice to move the sparrow format specific code to armory as part of armory3d/armory#2745.

For example we do this with physics where the desired engine can be selected during build time https://github.com/armory3d/armory/tree/main/Sources/armory/trait/physics.

Perhaps a similar setup could work for tilesheets, residing in armory/trait/tilesheet. If the sparrow format is used, then it gets included, otherwise it's left out completely.

@rpaladin
Copy link
Contributor

rpaladin commented Jan 10, 2023

Hi @mastereric, just a friendly reminder, Lubos is awaiting the suggested changes. 🙂 If you'd like your PR (notice singular, not plural) to be merged, you'll need to implement the suggested changes. If you don't know how to implement the suggestions, feel free to ask for help on Discord or the forum. (This helps prevent spamming of GitHub notifications for numerous people.)

@luboslenco
Copy link
Member

Keeping open at armory3d/armory#2745. Still happy to merge changes to iron but we should only include sparrow functionality if it is used in a project. Also happy to help more if needed!

@luboslenco luboslenco closed this Feb 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants