Game Development Reference
In-Depth Information
for (int i = 0; i < [shieldOnAtlas.textureNames count]; i++) {
NSString *tempName = [NSString
stringWithFormat:@"shield%.3d", i];
SKTexture *tempTexture = [shieldOnAtlas
textureNamed:tempName];
if (tempTexture) {
[self.shieldOnFrames addObject:tempTexture];
}
}
self.shieldOffFrames = [[NSMutableArray alloc] init];
SKTextureAtlas *shieldOffAtlas = [SKTextureAtlas
atlasNamed:@"deplete"];
for (int i = 0; i < [shieldOffAtlas.textureNames count]; i++)
{
NSString *tempName = [NSString stringWithFormat:@"deplete%
.3d", i];
SKTexture *tempTexture = [shieldOffAtlas
textureNamed:tempName];
if (tempTexture) {
[self.shieldOffFrames addObject:tempTexture];
}
}
9. Same as before, we create arrays and populate them with textures extracted
from texture atlases.
10. In order to test the shielding functionality, you can add
self.shielded = NO
to the
startRunningAnimation
method, and
self.shielded = YES
to
the
startJumpingAnimation
method. This way, while you are in the air,
the shield will work, but if you touch the ground, it will fade away.
Build and run the project now to see if everything runs as expected.
Now that we have most of our animations out of the way, we can recall the process
of adding animations to the node:
•
Create an array to hold animation frames
•
Extract textures from the texture atlas by iterating over it in a loop
•
Create a method to run the animation action on the needed node
•
Remove the action from the node if needed