Adding the Blind Scientist Behaviors
Before we define the behaviors for the Blind Scientist, we should spend a little bit of time explaining the XAML that defines the Blind Scientist actor. Inside the Blind Scientist's XAML definition is a Silverlight Storyboard (a time-based animation) that will grow the Blind Scientist in size by 400%. We want to create a behavior that will run the Storyboard animation when our Main actor first collides with the Blind Scientist. Because we don't want the Blind Scientist to grow 400% for every collision with the Main actor, we'll also use a custom property, isHit
, as a Boolean field to see whether the growth animation has already executed.
Adding a Custom Code Behavior to Call the Grow Animation Storyboard
To begin, create a new custom code behavior for the Blind Scientist actor and rename the behavior to "RunGrowStoryBoard". Set the event that will run this behavior to be a collision event between the Blind Scientist and the Main actor, as shown in Figure 2-70.
Figure 2-70. The collision event to run the custom code behavior
Next, click the Filter button for the "RunGrowStoryBoard" behavior, as shown in Figure 2-71.
Figure 2-71. Adding a filter to an event's behavior
As we explained earlier, a behavior filter lets you filter events so that the behavior ...
Get Coding4Fun now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.