FAT Pet Advanced

If you have never created a pet for Whirled, you probably want to look into our FAT Pet Tutorial. If you feel sufficiently experienced, feel free to move forward with the more advanced steps below.

Basic Settings
You can configure your basic document properties under Modify &rarr; Document....
 * Dimensions: A pet may be any size under the maximum of 450x500 pixels.
 * Frame rate: All Whirled pets must be 30 frames per second.
 * Background color: You can use any background color you like, but it won't appear in Whirled.

Pet Scenes
A pet's behavior is all controlled by scenes and the names you give them. There's no code involved - just use the right naming convention, and Whirled will automatically incorporate your scenes into the pet's routines. Look at the examples in each category to see how scene naming defines what a scene does.

Moods
A pet's moods will change randomly, according to the whim of the pet. For any mood there must be an idle scene, and all pets require a base "content" mood.

The default moods defined by the SDK are:
 * content_idle
 * hungry_idle
 * playful_idle
 * sleepy_idle
 * sleeping_idle
 * lonely_idle
 * curious_idle
 * excited_idle

Walking
Walking scenes are triggered whenever your pet traverses space in the room. You can associate walks with any moods you've created. If a mood doesn't have an associated walk, your pet will just transition to "content" before moving.

Some example walks:
 * content_walk
 * hungry_walk
 * playful_walk



Transitions
Transitions are special scenes that smooth the change from one scene (mood or walk) to another. They will be played through once before beginning the scene called. For example, if the pet decides to start flying, Whirled will play content_to_flying once through before beginning flying_idle. You don't need transitions for all or even any of your moods. Just transition the ones you want.

Some example transitions:
 * Transitioning to and from a walk:
 * content_towalk
 * content_fromwalk
 * Transitioning between two moods:
 * playful_to_content
 * content_to_hungry

It is also possible to limit what mood changes your pet can have. These are the default changes:
 * content changes to playful, excited, curious, hungry or lonely
 * playful changes to content, sleepy, or excited
 * sleepy changes to sleeping
 * lonely changes to content or sleepy
 * hungry changes to content, lonely or curious
 * curious changes to content, hungry or excited
 * excited changes to content, playful or curious

Incidentals
Sometimes you want a mood to vary. For instance, in an idle animation, you want the pet to yawn every so often. These are called incidentals, and can be handled with scene naming, just like other animations. Essentially, you split up the mood into multiple numbered versions (01, 02, 03...) and then assign each numbered version a percent probability (:05, :80, :66...) so that the versions' probabilities add up to 100. When a given scene of a mood is finished, Whirled will randomly choose the next version of the mood to be played, based on these probabilities.

Some example incidentals:
 * An occasional yawn in the content mood:
 * content_idle_01:95
 * content_idle_02:05
 * A mood that equally mixes three possible animations:
 * playful_idle_01:34
 * playful_idle_02:33
 * playful_idle_03:33

Pet Code
Just as a typical Whirled pet is built in Adobe Flash CS3, the code to handle pets is written in Flash's ActionScript. Moving beyond the basic pet template doesn't require complex code writing. Setting up new actions for your pet is usually as easy as cut and paste.
 * 1) If you haven't yet, download the Whirled SDK.



Required ActionScripts
Whirled pets require some ActionScript to communicate with Whirled's servers and let each other know what's going on. The basic code tells the pet which way it's facing and whether or not it's walking. This pet foundation code is a combination of imported scripts from the Whirled SDK and a few lines of ActionScript in the main scene. In the template we already did this for you. If you make a pet from scratch, or open the source file for someone else's pet, you'll need a basic understanding of how to set it up yourself.

Classpaths to Import Whirled's Server Code
Setting a classpath in Flash's preferences means it will automatically import this code for all your future pets. Once it's set up, all your avatars will export with the server code.
 * 1) In Flash, choose Edit -> Preferences.
 * 2) Under Category, choose ActionScript.
 * 3) Click the button labeled "ActionScript 3.0 Settings...".
 * 4) Add the base Whirled classpath:
 * 5) Click the plus to add a new classpath.
 * 6) Click the crosshairs to browse to your SDK folders.
 * 7) Find and set the path to "...\whirled\src\as".
 * 8) Add the pet classpath:
 * 9) Click the plus to add a new classpath.
 * 10) Click the crosshairs to browse to your SDK folders.
 * 11) Find and set the path to "...\whirled\examples\pets\urpet\src".



Basic ActionScript for the Main Scene
The "main" scene of your pet file should contain all the code for handling pet behavior in Whirled. For a basic pet, this is a simple copy and paste. import com.whirled.PetControl;
 * 1) Select the scene "main". If this is a new file, double-click "Scene 1" to rename it "main".
 * 2) Open the Actions window (F9).
 * 3) Paste in this code and replace w with the width of your scene.

if (_ctrl == null) { _ctrl = new PetControl(this); _body = new Body(_ctrl, this, w); _brain = new Brain(_ctrl, _body);

addEventListener(Event.UNLOAD, handleUnload);

function handleUnload (... ignored) :void {     _brain.shutdown; _body.shutdown; } }

var _ctrl :PetControl; var _body :Body; var _brain :Brain;

Hotspot
The hotspot determines where the pet sits on the floor of a room. The default hotspot is the center of the lowest point on the pet. _ctrl.setHotSpot(x, y);
 * 1) Add this line of ActionScript directly under your existing "_ctrl..." lines.
 * 2) Click the Info tab.
 * 3) Move your cursor over the point on the "floor" directly below your pet's center of gravity.
 * 4) Note the coordinates of your cursor in the Info tab.
 * 5) Replace the x and y in the script with the x and y coordinates of your newfound hotspot.

Move Speed
The move speed is the rate at which your pet will traverse a room at full size, in pixels per second. The default move speed is 400. Lower numbers are slower and higher numbers are faster. _ctrl.setMoveSpeed(n); Upload to Whirled and check your walk speed in action. Then go back to your source file and adjust up or down.
 * 1) Add this line of ActionScript directly under your existing "_ctrl..." lines.
 * 2) Replace the n in the script with the speed you want for your pet.


 * Tutorials From All Over courtesy of coldhardflash.com
 * Introdution to ActionScripting by Dan Livingston
 * Introduction to Actionscripting by James Rice