CAAT.Actor

CAAT.Actor is the simplest object instance CAAT manages. Every on-screen element is an Actor instance. An Actor has entity, it has a size, position and can have input sent to it. Everything that has a visual representation is an Actor, including Director and Scene objects.

This object has functionality for:

  1. Set location and size on screen. Actors are always rectangular shapes, but not needed to be AABB.
  2. Set affine transforms (rotation, scale and translation).
  3. Define life cycle.
  4. Manage alpha transparency.
  5. Manage and keep track of applied Behaviors. Behaviors apply transformations via key-framing.
  6. Compose transformations. A container Actor will transform its children before they apply their own transformation.
  7. Clipping capabilities. Either rectangular or arbitrary shapes.
  8. The API is developed to allow method chaining when possible.
  9. Handle input (either mouse events, touch, multitouch, keys and accelerometer).
  10. Show an image.
  11. Show some image animations.
  12. etc.

This class is the superclass for other Actors, so it must be specialized to perform new behaviors. There some out-of-the-box Actors already available in CAAT:

  • Label. Shows multiline text with embedded font styles.
  • Dock. A container which behaves like OSX's dock.
  • TextActor. Show single line text with a font or Sprite font.
  • ShapeActor. Shows rectangles or circles.
  • StarActor. Shows an star where you can customize number of vertex, radius, etc..
  • InterpolatorActor. Shows curves for CAAT.Behavior.Interpolator objects.
  • PathActor. Shows and handles a CAAT.PathUtil.Path object.
  • ...

but as you'll see, developing a new breed of Actors will be just a few lines of code.

Take a look at Sumon sourcecode: https://github.com/hyperandroid/Sumon which defines lots of new Actors.

One important fact about Actors is the coordinate system. An Actor will always report local coordinates despite the transformation applied to it. In example, an Actor can be scaled twice widely, and rotated 45 degrees, and on mouseMove the received event will report local Actor coordinates as if the actor itself weren't transformed.

Additionally, each actor defines anchors por position, rotation and scale independently. See methods setPositionAnchor( ax, ay ); setRotateAnchor( ax, ay ); and setScaleAnchor( ax, ay );. Anchors are defined in relative coordinates, so if for example, a rotation anchor by an actor's center is to be set, you must call setRotateAnchor(.5,.5);