12/24/2022 0 Comments Codeandweb texturepacker![]() ![]() Local comp = hud.getComponent ( application.getCurrentUser ( ),sComp ) Local v = 1-( string.toNumber ( xml.getAttributeValue ( xml.getElementAttributeWithName ( e, "y" ) ) ) / imgHgt )-vscale Local u = string.toNumber ( xml.getAttributeValue ( xml.getElementAttributeWithName ( e, "x" ) ) ) / imgWid Local vscale = string.toNumber ( xml.getAttributeValue ( xml.getElementAttributeWithName ( e, "h" ) ) ) / imgHgt Local uscale = string.toNumber ( xml.getAttributeValue ( xml.getElementAttributeWithName ( e, "w" ) ) ) / imgWid If ( sIcon=xml.getAttributeValue ( xml.getElementAttributeWithName ( e, "n" ) ) ) then ![]() Local imgHgt = string.toNumber ( xml.getAttributeValue ( xml.getElementAttributeWithName ( r, "height" ) ) ) Local imgWid = string.toNumber ( xml.getAttributeValue ( xml.getElementAttributeWithName ( r, "width" ) ) ) Local r = xml.getRootElement ( this.xmlZS_icons ( ) ) (I call my xml variable xmlZS_icons, and hard-code that in the code below) LUA CodeĪdd the following function to your AI: -įunction MyAI.SetUvsFromTextureAtlas ( sComp,sIcon ) Anywhere you want a texture out of the atlas, just set that HUD component to the Atlas texture (it looks a bit weird at design-time.)Īdd an XML variable to an AI, and set it initialised from the imported xml. Import the xml file and texture atlas in to Shiva. It simply encodes the names of the images (sprites), along with their positions and sizes in the atlas. My Shiva code a bit later will assume the following format, which is what Texture Packer gives us. I use a program called Texture Packer ( /texturepacker) for this, which combines your textures into a single PNG and also exports an XML description of it (which we’ll need later we could of course manually write the XML but it’s a bit more work that way.) But it can be a bit fiddly calculating the UVs, especially if you want to add new textures to it later. This means that only one texture has to be referenced by the graphics hardware. ![]() The idea is that you pack lots of textures into one big one, and then use UV offsets to define which region of this large texture to display in your HUD components. As you probably know, it’s important to use Texture Atlases for efficiency reasons on mobile devices. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |