Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
So now that we've created our main sprite sheet in TexturePacker, we need to use both the PNG and the XML file to create a texture atlas, so that we can reference those assets in Starling. So I'm going to come into my asset class right under where I created or embedded the sky.png and we need to embed both that atlas.png and also the atlas.xml. So I'm going to start with the PNG. So Embed source and that is assets/atlas.png and I'm going to create a private static variable which is going to hold a class variable so we can instantiate that.
So it's going to be private static var and I'm just going to call it atlas. Now when we create our texture atlas, I want to create that as a public static variable, so that we can actually reference it from anywhere we want in our game. So I'm going to create another variable here public static var, and I'm going to call it ta for TextureAtlas, and this is going to be of type TextureAtlas. So now I need to embed that XML file. So it's going to be a similar thing, I'm going to say Embed (source="assets/atlas.xml", but the difference is when we are dealing XML files is we also have to set the mime type to application octet stream, so let me do that now.
mimeType="application/octet-stream") and now we're going to create a private static variable called atlasXML. So now I have both the PNG and the XML embedded and I also have that public static variable, which is going to hold my TextureAtlas. Now I'm going to come down into the init function and instantiate that. So I'm going to instantiate the ta variable, is equal new TextureAtlas, and to this we need to pass in the texture that we're going to create from that PNG, and also the XML file.
So we're going to use the Texture.fromBitmap factory method and we're going pass in a new instance of atlas, because remember that's the embedded PNG file. Now the next thing we need to pass in is the XML file. When we instantiate atlasXML we are going to need to cast it to an XML object, so we are going to cast it like that and pass in a new atlasXML. So let me close that, close that, and close that.
So I've now instantiated my TextureAtlas, and you'll see as we go through the course, I'm going to easily be able to use this ta variable, and say ta.gettexture and give it a string name for the texture that I want to retrieve, but again, the main benefit of this is I'm not having to embed all of these different images separately causing different network requests, and so on, and so forth. So putting them together into a TextureAtlas, not only makes it a lot easier as you are building your game, but also greatly improves the performance of your game.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 104889 Viewers
56 Video lessons · 116749 Viewers
71 Video lessons · 85966 Viewers
131 Video lessons · 41115 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.