Game Development Reference
In-Depth Information
[self.shield removeActionForKey:@"shieldOn"];
[self.shield runAction:[SKAction animateWithTextures:self.
shieldOffFrames timePerFrame:0.15 resize:YES restore:NO]
withKey:@"shieldOff"];
}
_shielded = shielded;
}
5.
First, we look for a new value that we are presented with. If it is YES and we
don't have the animation running, we start the shield on animation. It repeats
itself since we want the shield to animate while it is on. If we are presented
with NO , the other portion of this method gets triggered. It checks if the player
was shielded before, and if it was, the character sprite blinks red, and it is time
to run the shield off the animation. If there was no shield before, we don't
want to play the shield dismissing animation. We want it to run only once.
We also don't want to have the shield on animation repeating itself, so we
remove the old action. After that, we set the shielded variable to the
provided value.
6.
Add the blinkRed method:
- (void) blinkRed
{
SKAction *blinkRed = [SKAction sequence:@[
[SKAction
colorizeWithColor:[SKColor redColor] colorBlendFactor:1.0
duration:0.2],
[SKAction
waitForDuration:0.1],
[SKAction
colorizeWithColorBlendFactor:0.0 duration:0.2]]];
[self runAction:blinkRed];
}
7.
This method makes our player sprite red for a short while and then
returns it back to its regular state. To do this, it uses an action named
colorizeWithColor: , waits a little, and proceeds to colorize with the
default value, which is 0.0 , meaning no colorization. The blend factor
specifies the amount of target color to be added to the existing texture.
The higher the blend factor is, the more intense is the color, and on 1.0 ,
all pixels of the texture will be of the chosen color.
8.
Next is the setupAnimations method; we need to add new textures to it:
self.shieldOnFrames = [[NSMutableArray alloc] init];
SKTextureAtlas *shieldOnAtlas = [SKTextureAtlas
atlasNamed:@"shield"];
 
Search WWH ::




Custom Search