Chapter 28. Animation

Earlier chapters have mentioned various ways to achieve animated effects in REALbasic: you can redraw parts of a Canvas, for example (Chapter 11), or use a MoviePlayer (Chapter 27). But REALbasic also provides a control class whose primary purpose is animation—the SpriteSurface control. Figure 28-1 shows an example of a SpriteSurface; it’s being used to play a little game, PacMan On Mars, which we’ll develop later in the chapter. But first, let’s start with the basics.

PacMan On Mars

Figure 28-1. PacMan On Mars

A SpriteSurface is a RectControl, and therefore receives all the events and has all the methods listed in Chapter 10: Open and Close events; Visible, Enabled, and AutoDeactivate properties; Top, Left, Height, and Width properties; LockLeft, LockRight, LockTop, and LockBottom properties; MouseEnter, MouseMove, and MouseExit events; and Refresh and RefreshRect methods. For drag-and-drop, see Chapter 24.

A SpriteSurface is a rectangular area of a window that functions as a “stage” within which animation can take place. A SpriteSurface can contain two sorts of thing:

The background

An image that fills the SpriteSurface. It can be animated by assigning a different image, or by scrolling.

One or more sprites

A sprite is an instance of the Sprite class. It has an image, which is drawn transparently in front of the background. It can be animated by changing its ...

Get REALBasic: TDG, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.