Actor Paths

From SCI Wiki
Revision as of 15:19, 5 August 2013 by Andrew Branscom (talk | contribs) (1 revision)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Chapter 3 - Making Actors Move Along Paths

*Requires SCI Studio 2.11 or higher.

Most likely in your game you will need to have actors moving. This is simply done by setting the actor's motion.

Getting Started

Open your game in the resource explorer and select "Resource"->"Add Sample"->"View"->"Brian" from the menu.

Save it to your game as view.001.

View

We'll begin with the basics by editing a view.

Rm001 Script You can obviously use this in any script, but for demonstration purposes, open up the game's "rm001.sc" script.

Since the ego is an actor, everything in this lesson can be applied to it as well. However, to keep things simple, we will create another actor. Scroll down to the end of the script and add the following lines of code:

Code:
(instance aMan of Act
  (properties
    y 170
    x 190
    view 1
  )
)

This simply creates an actor which uses view.001 and positions it at (190,170).

Game Instance Next, go to the game's instance, then scroll down to the bottom of the init method.

Set up the actor with the following lines of code:

Code:
(aMan:
  init()
  setCycle(Walk)
)

This simply initializes the actor, then sets it's cycle to Walk. If the cycle wasn't set, it would just drag across the screen. It's now ready for it's movement to be set up.

Simple Actor Movement

Setting up an actor to move from it's current position to another is very simple. All you need to do it call it's setMotion() method, and set it's motion to MoveTo. This method takes three additional parameters: the X coordinate, the Y coordinate, and the room script. The X is of course, the amount of pixels from the left of the screen the actor will be positioned, and the Y being the amount of pixels from the top. The room script is used to trigger an event. Just set it to the current room script.

To implement it, you can simply adjust the initialization of the actor and add a MoveTo setMotion:

Code:
(aMan:
  init()
  setCycle(Walk)
  setMotion(MoveTo 180 150 RoomScript)
)

The actor is now set to move to the coordinates (180,150).

That's all there is to it!

Moving Actors Along Paths

Moving actors along paths requires the DPath motion. You simply call the setMotion method and set the motion to DPath. It takes an unlimited amount of parameters. You just add the X,Y coordinates which is should move.

To implement it, you can simply adjust the initialization of the actor and add a MoveTo setMotion:

Code:
(aMan:
  init()
  setCycle(Walk)
  setMotion(
     DPath
     180 150
     240 100
     280 160
     180 150
  )
)

This sets up the actor to move to (180,150), then up to (240,100), then down to (280,160), then back to it's starting position, (180,150).

Compile and run and you'll see the actor move just like that!

Setting An Actor's Motion Anywhere

In the preceding examples, the actor's motion was set in the init() method. However, it can be called from anywhere in the script.

Here's an example of using it anywhere:

Code:
(aMan:setMotion(MoveTo 180 150 RoomScript))

That sums up actor movement! For more complex movement, have a look at the chapter [chapter04.html Moving Actors and Triggering Events.]

Congratulations! You now know how to edit view resources.  

< Previous: Chapter 2 - Oh, yeah? Well, "%s" this! Next: Chapter 4 - Moving Actors and Triggering Events >