Exercise
The example project that is provided with this chapter, CH06_SLQTSOR, displays three different images that have been taken from a single sprite sheet. These images are scaled, rotated, and colored using the features of the Image class covered in Chapter 5 to show that the Image instance returned is an entirely separate image in its own right.
The current project is using a couple of sprite sheets from Sir Lamorak's Quest that have been placed inside a complex sprite sheet.
Using this project as a guide, why not try to create your own basic sprite sheet or download one from the Internet? Once you have your sprite sheet, create a complex sprite sheet using Zwoptex and then render your sprites to the screen.
Here are the steps you need to follow:
- Decide what fancy sprites you want to create.
- Work out the dimensions each sprite is going to be (for example, 40x40 or 50x80) and any spacing you want to use.
- Open up your favorite graphics package and draw your sprites, remembering to keep each sprite in a square that has the dimensions you decided.
- Export your sprite sheet as a PNG file.
- Open up the Zwoptex link (www.zwoptexapp.com/flashversion/), and add the sprite sheets that are included in the project along with your own.
- Export the texture and coordinates from Zwoptex.
- Add the two files you have just generated to the Xcode project. This can be done by right-clicking the Images group inside the Game Resources group and selecting Add > Add Existing File. Inside the panel that pops up, navigate to the file and select it. You should also select the Copy option to make sure the files are copied to the project folder.
- Finally, follow the code example in the current project to import and start using your sprite sheet.
- Once you are rendering your sprites, try to apply some image functions, such as scaling, rotation, and color.