Translations of this page:

5. Actors

The following chapter covers actors in general and also deals with the details of the 2D – sprite actor – creation. For those who are interested in 3D actors is then dedicated the chapter called “Going 2.5d” so have patience, we’ll get to it too.

We’ve already seen a few methods associated with actor – we’ve seen how to load actor to game or to the current scene, we know how to make our actor walk, talk, set direction he is facing etc. But let’s see, how does Molly look. Open the file data\actors\molly\molly.actor and immediately see that it’s not a script file - it’s a definition file.

Let’s split it by little chunks and explain the whole file:

; $EDITOR_PROJECT_ROOT_DIR$ ..\..\..\

Normally in the WME definition files lines starting with ; are commented out. Note that the script comments

(// or /* */) are not supported in definition files and will cause an error!

But this line is special and it tells WME how deep we’re in the folder structure or in other words where is the root of the project. This is very important later on in scene files, where (if you move scenes around into deeper directory structures, you should adjust this value or your scene won’t work).

Important: Lines in definition files don’t end with a semicolon!

ACTOR 
{

Our datablock defining an actor starts with:

  NAME = "molly" 
  CAPTION="" 
  SCALABLE = TRUE 
  INTERACTIVE = FALSE 
  X = 400 
  Y = 460 
  SCRIPT="actors\molly\molly.script" 
 
  FONT = "fonts\outline_red.font"

NAME is the internal name of an actor. CAPTION is the label which can be used for example in game_loop.script to display the caption in the same way as with the Nodes. SCALABLE can be true or false and defines if actor is affected by Scene scale levels or by manually scaling it through internal method. In addition we can have:

ROTATABLE = TRUE/FALSE which would make our character affected by the scene rotation levels which we’ve seen already in the Scene Edit.
INTERACTIVE means that the actor is sensitive to mouse. If you run our game now and put mouse cursor over Molly, game doesn’t react because the INTERACTIVE is set to false. If you changed this to TRUE you’d see that Molly is an interactive part of the scene as well.
X and Y are the initial coordinates of an actor on screen.
SCRIPT is a script filename which will be automatically attached to the actor upon loading. You can have multiple script lines there. FONT is the font file used for actor.Talk method we’ve used already.

And there are two more:

SOUND_PANNING = TRUE/FALSE which if set to true would automatically pan the sound from left to the right according to actor’s onscreen position.
COLORABLE = TRUE/FALSE which if set to true would make the actor affected by the decoration regions.

Now before we go on, let’s have a little bit of theory. To have a successful 2D actor in our scene, we need to define five basic sets of animations (walk, talk, idle, turnleft, turnright).

WME documentation clearly states that: “…remember the actor is able to walk into eight directions, therefore you will need eight versions of each animation type for different directions. If you have only four directions created for your character, you can use one animation for multiple directions, but the actor definition file must always define all 8 directions. For example if you have a "character walking left" animation, you can assign it to both "walk left" and "walk up left" directions.“

But let’s look at our first animation set called walk - note that the behavior changed in new WME (before it was SPRITESET).

  ANIMATION 
  { 
    NAME       = "walk" 
 
    LEFT       = "actors\molly\ll\walk.sprite" 
    RIGHT      = "actors\molly\rr\walk.sprite" 
    UP         = "actors\molly\uu\walk.sprite" 
    DOWN       = "actors\molly\dd\walk.sprite" 
 
    UP_LEFT    = "actors\molly\ul\walk.sprite" 
    UP_RIGHT   = "actors\molly\ur\walk.sprite" 
    DOWN_LEFT  = "actors\molly\dl\walk.sprite" 
    DOWN_RIGHT = "actors\molly\dr\walk.sprite" 
  }

As you see, you assign different sprite for each of the eight possible directions and that’s about it. There’s one special thing about walking animations though – when you construct your actor’s animation in the Sprite Edit, you have to set the “Move by” parameter for each frame as we discussed before. This will define how fast the character moves on the screen.

Next sprite set is called idle.

  ANIMATION 
  { 
    NAME       = "idle" 
 
    LEFT       = "actors\molly\ll\stand.sprite" 
    RIGHT      = "actors\molly\rr\stand.sprite" 
    UP         = "actors\molly\uu\stand.sprite" 
    DOWN       = "actors\molly\dd\stand.sprite" 
 
    UP_LEFT    = "actors\molly\ul\stand.sprite" 
    UP_RIGHT   = "actors\molly\ur\stand.sprite" 
    DOWN_LEFT  = "actors\molly\dl\stand.sprite" 
    DOWN_RIGHT = "actors\molly\dr\stand.sprite" 
  }

There’s nothing special about idling around. You can add some neat effect like breathing, shuffling feet or scratching nose.

Next two sprite sets are called turnleft and turnright and via them can be achieved realistic turning of actor. Default is just a flip which we know from older games. They look identical so I’ll include only turnleft.

  ANIMATION 
  { 
    NAME       = "turnleft" 
 
    LEFT       = "actors\molly\ll\turn.sprite" 
    RIGHT      = "actors\molly\rr\turn.sprite" 
    UP         = "actors\molly\uu\turn.sprite" 
    DOWN       = "actors\molly\dd\turn.sprite" 
 
    UP_LEFT    = "actors\molly\ul\turn.sprite" 
    UP_RIGHT   = "actors\molly\ur\turn.sprite" 
    DOWN_LEFT  = "actors\molly\dl\turn.sprite" 
    DOWN_RIGHT = "actors\molly\dr\turn.sprite" 
  }

Last set is the talk animation.

  ANIMATION 
  { 
    NAME       = "talk" 
 
    LEFT       = "actors\molly\ll\talk.sprite" 
    RIGHT      = "actors\molly\rr\talk.sprite" 
    UP         = "actors\molly\uu\talk.sprite" 
    DOWN       = "actors\molly\dd\talk.sprite" 
 
    UP_LEFT    = "actors\molly\ul\talk.sprite" 
    UP_RIGHT   = "actors\molly\ur\talk.sprite" 
    DOWN_LEFT  = "actors\molly\dl\talk.sprite" 
    DOWN_RIGHT = "actors\molly\dr\talk.sprite" 
  }

We can define more than one talk blocks though! If we do, WME then randomly plays the talk animations while talking which makes it more alive. In addition to that we can define a Talk stances which will be invoked through the special parameter in the Talk command.

If we created a special animation and name it for example eyeroll, we could then for a special line invoke the eyeroll.

So let's recap - by default if we call actor.Talk(“Hello, how is it goin? Blah blah blah”); all animations named talk are randomly played.

Full method is actor.Talk(Text, SoundFilename, Duration, TalkStances, TextAlignment)

Text – is the written line. So far we always used solely this parameter.
SoundFilename – this is in a way an obsolete parameter. We’ll see why when we get to the localization chapter, because in the latest engine versions, WME automatically chooses a correct filename to play according to string tab file. So if you’re going to use voiceovers, simply put null in there.
Duration is normally not used as well. Text is automatically synchronized to speech file. You can use null again.
TalkStances – here you can specify the order and stances, which are used for the speech. If this parameter is supplied you can choose only a subset of stances.
TextAlignment – defines the alignment of the written lines.

So our modified call could look like for example:

actor.Talk("Hello.",null,null,"eyroll"); which would make actor perform an eyeroll on this line.

As a side note - we’ve used always only variable actor for actor interaction, but it’s only a variable. So if I wanted to break this stereotype I can easily do the following:

in base.inc declare

global Peter;  
global Sally;

in game.script use our

Peter = Scene.LoadActor("path_to_peter.actor file"); 
Sally = Scene.LoadActor("path_to_sally.actor file"); 
 
Peter.GoTo(100,100); 
Sally.Talk("blahblahblah");

I think you’ve got my point here. But back to animations.

You can of course create also sprites for nonstandard animations (pickup, push, pull etc.) which will be then referenced from the scripts.

So we see that it’s not hard to create a brand new 2D actor, together with animations, provided we have a corresponding graphics. And now it’s time to discover some more usable methods for actors.

actor.PlayAnim(path_to_sprite) – plays an animation as defined in sprite file and wait until the animation is finished.
actor.PlayAnimAsync(path_to_sprite) – plays an animation as defined in actor file and immediately continue.
actor.Reset() – cancel current action actor is performing (talking, walking)
actor.TurnTo(object or direction) – makes actor turn either to an object’s direction as defined in Scene Edit or to directional constant.

Lastly you can override the default animations (for example run, swim or fly animation to replace "walk") and switch them using the actor.TalkAnimName, actor.IdleAnimName, actor.WalkAnimName, actor.TurnLeftAnimName and actor.TurnRightAnimName.

This book doesn’t surrogate WME documentation. There are other methods and attributes which can be used for our actors. So as I promised in the first chapter, I’ll include on closing relevant sections in WME documentation, where you can see the complete object description.

Contents→ Inside a game→ Actors - for the general description of actor
Contents → Scripting in WME → Script language reference → Actor object – for methods and attributes which can be used with the actor

 
wmebook/ch5.txt · Last modified: 2008/01/10 11:57 by metamorphium
Recent changes RSS feed Creative Commons License Driven by DokuWiki