Chapter 4: Loopers

The View class has a setLoop method that indicates which loop in the view should be used.  The Act class extends this by allow you to specify an object than can control which loop is shown, based on the actor’s heading.

To make a looper object, you can make an instance of the base class Obj, and provide an init method that takes one parameter (the actor), and a doit method that takes 2 parameters (the actor, and its heading).  The game will call the doit method only when the heading changes.

Reversing the up and down loops

For this exercise, we’ll make a looper that switches the normal up and down loops used when an actor is moving around.  Generally, loop 3 is used when the actor is heading “up” (facing away), and loop 2 is used when he is heading “down” (facing you).  To make it so he faces away when he moves down, and faces you when he moves up, we could write the following looper:


(instance myLooper of Obj



   (method (init client)


   (method (doit client heading)

      (if ((< heading 45) or (> heading 315))

         (send client:loop(2))

      )(else if ((>= heading 45) and (<= heading 135))

         (send client:loop(0))

      )(else if ((> heading 135) and (< heading 225))

         (send client:loop(3))


         (send client:loop(1))




The looper needs to at least have those two methods, or it will crash.

And then, you need to apply the looper to the actor:

For example:

        (send gEgo:setLoop(myLooper))


Unfortunately, there is no way to “remove” a looper and return to the default behaviour, although it does get reset each time the actor is initialized (e.g. so in this case, it will be reset when the ego moves to the next room).

< Prev Back to Tutorials Next >