Game Development Reference
In-Depth Information
Go ahead and add this class as a component to the Enemy_Drone object in the scene. The
PingPongSpriteColor class supports a range of public member variables, including Source and Dest
colors, representing the color to blend with the sprite material using multiplicative blending. Source
defines the default color to be blended with the sprite when it's not being attacked (this should be
white to preserve the default colors defined in the sprite texture file), and Dest defines the blending
color when the sprite is under attack (and this should be red ). This is because the sprite should
turn red when being attacked. The transition time defines the total time in seconds for the sprite
to change color from its default (white) to red when being attacked. For the Drone character, I've
specified a value of 0.3 seconds (see Figure 7-10 ).
Figure 7-10. Configuring color animation for the sprite material
Just adding PingPongSpriteColor as a component to the game object isn't enough, however,
for turning the Enemy red when attacked. We'll need some extra code in the Damage event for
Enemy_Drone to initiate the red-flashing behavior at the appropriate time. Consider the amended
Damage event in Listing 7-4. The Damage event now calls on the PingPongSpriteColor function
PlayColorAnimation (as defined at line 31 in Listing 7-3).
 
Search WWH ::




Custom Search