How to Use the atlasc texture set (generated using TexturePacker) when developing a game using SpriteKit in xcode7.3)

Source: Internet
Author: User
Tags spritekit

How to Use the atlasc texture set (generated using TexturePacker) when developing a game using SpriteKit in xcode7.3)

Because the resource file to be used is a small set of images, we need to first generate a large image and include all the small images in it, the best way is to use a third-party tool to implement this function.


1. First download TexturePacker. The latest version when writing this article is 4.1.0.

For: https://www.codeandweb.com/blog/2013/09/23/spritekit-animations-and-textureatlases


2. Start TexturePacket and drag the prepared image to the workspace. The image is automatically changed to an image.

I made a 10-Digit Image and dragged it to the project. The effect is as follows:



3. After dragging the resource file, you need to select the data format. Because I use Apple's SpriteKit instead of a third-party framework such as cocos, You need to manually modify DataFormat, as shown in:



4. use Atlas bundle to set the location of the input file. The generated file name is textureNumber. atlasc and set the Header file, as shown in. After all settings are complete, click the Publish Sprite Sheet button. If no problem occurs, the file we want will be generated. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20160422/20160422091001582.png" alt = "\">


5. Open the Finder and find the file location we specified above. You will see a directory and a header file. The directory also contains two files, a png file and a plist file.




6. Drag the generated directory and header file to our project (Xcode). In the displayed dialog box, select create folder references and confirm to targets selection.



7. next, we can use the resource file we just added. First, add the reference of the newly generated header file in the scenario file we want to use, # import "textureNumber. h ", the header file contains the macro definition of all resources for our convenience. The file content is as follows:



8. Add the following test code to the didMoveToView method in the current scenario GameScene. m file:



9. Compile and run our existing game program to see the effect. A picture of 0 is displayed at the bottom of the screen.



10. now the problem arises. There are multiple such images in a game. I may add multiple atlasc texture sets by category, such as digital image sets, bullet image machines, and role image sets, to make the directory classification clearer, I created a resource Directory and put multiple image sets under the same directory for Management (blue folder). The directory format will be included in the packaged app, as shown in.



11. in order to do a test, the title of the small image in the texture set I created for the second time is exactly the same as the name of the image I created for the first time. It is also 0, 1, 2, 3 ..... so what will happen? Run the previous program to check the effect.

As shown in, we can see that the previous 0 does not exist, and a Red Cross is displayed, which indicates that the resource loading error has occurred and our resource cannot be found.



12. there are two problems. One is that a directory is added, and the path cannot be found. The other is that the image name is duplicated and the system does not know which one to load, in this way, we load the specified texture set first and then obtain the texture resources contained in it. The solution is as follows:



13. to compile and run the program again, we 'd better clean the project first and then compile and run the program. We can see that the texture 0 is displayed again. Although the results are the same as before, the implementation scheme is completely different, the following methods are more suitable for use.




10. in summary, loading with a texture set can effectively improve the efficiency of game execution. When there are too many image resources, it is more suitable for classification management and is a better way to use resource images in games.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.