Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBrock Ormond
7,176 PointsTexture Atlas in reverse?
What if we start with an image that has all our sprites in it, but do not have a plist to sort it out. What is the preferred method to 'reverse engineer' the plist or how to create an atlas when all the sprites are on a single image already? For Example, a deck of playing cards....
1 Answer
Michael Blazek
162 PointsTo do this you could load the texture then use the textureWithRect method where you would pass the rect that is the individual piece you want out of the whole sheet, say for each card.
SKTexture *temp = [SKTexture textureWithRect:piece inTexture:sheet];
Sheet would be the original texture piece is a CGRect of size and location inside the sheet for the piece you want
temp would be the resulting texture.
Brock Ormond
7,176 PointsBrock Ormond
7,176 PointsOkay, I see how that would work. Is it better to do that then say; make the plist file for it (can you)? What tool is best for finding those rect dimensions in either case? Most of my programming experience is doing backend coding, very little graphic experience; so I may be missing the obvious.
Michael Blazek
162 PointsMichael Blazek
162 PointsThird Party tools like texturePacker generate sprite sheets for Sprite Kit and use a pList file to do so. There are conventions you can follow if you dig deeper into Apple's documentation.
The real question for me would be why are you using a single image instead of a different one for each. What Xcode does for you is generates the single Texture automatically, which is a huge benefit of using Sprite Kit to build an iOS game.
But in the days before Sprite Kit, the artist would lay out images into a sprite sheet and then give the coordinate locations for each. You would then store the fileName (original file name of the single image) in a pList file and you would record in a dict the location, rotation, and trim. Then read out and cut up a texture. I wouldn't recommend doing it this way now.
Xcode will do all of this for you if you use the atlas folder btw.
Brock Ormond
7,176 PointsBrock Ormond
7,176 PointsIt wasn't so much 'wanting' to do it that way; it's what I found while googling for (in this case, card images). The ones I found were already in a single pic and was looking for an easy way to access the individual cards. It was for sake of convenience rather than desire.
Did not see the point of breaking up a picture into individual and then recompile into a new atlas. Was looking for a work around.
Michael Blazek
162 PointsMichael Blazek
162 PointsYour causing yourself more work then necessary, and you are not utilizing the tool you have in Sprite Kit. However I will tell you how I would go about it.
You have the image that you found online. You will need to determine in pixels how big each card is (Usually the artist would tell you this sort of thing, but i am assuming your using open source). Then you can write each card into a plist file with a x and y location and size. Then you can use the method I mentioned earlier.
You could also see how sprite kit breaks down an atlas to be an atlasc file that contains and image and plist, then you should be able to copy what they did and put the file in the right place and it should load on start up.
If you would like to use Sprite Kit and Xcode's atlas system you can use these free assets which have the cards as individual sprites for 3 types of decks: http://www.ironstarmedia.co.uk/2010/01/free-game-assets-08-playing-card-pack/
Brock Ormond
7,176 PointsBrock Ormond
7,176 PointsThanks for the help. Like I said before, doing graphics is still new to me so this was more a thought exercise on how to do something with limited resources.
Thanks for the link btw, it'll simplify my current project alot. Still need to make jokers for it though ;p