O'Reilly logo

REALBasic: TDG, 2nd Edition by Matt Neuburg

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Basic Sprite Techniques

To create a Sprite instance, use New. To give a SpriteSurface ownership of a Sprite, send the SpriteSurface the Attach message, handing it the Sprite; the SpriteSurface henceforward will draw the Sprite in accordance with the Sprite’s various properties. For example, if the Sprite’s X is 0 and its Y is 0, then the Sprite’s image will visibly appear at the upper left of the SpriteSurface the next time the SpriteSurface draws a frame. To detach a Sprite from its SpriteSurface, send the Sprite the Close message.

A Sprite has the following properties:

Image

The Picture displayed as the Sprite image.

X, Y

The coordinates of the Sprite image’s top left, with respect to the top left of the SpriteSurface that owns it.

Priority

A nonnegative integer; the lower the value, the earlier in the redraw process the SpriteSurface will redraw this Sprite. When there are many Sprites, this can help maintain smoothness of animation, because you can make sure that the Sprites redrawn first are the ones the user is paying closest attention to. Or, you can use this property in a different way: a Sprite image drawn later will appear on top of a Sprite image drawn earlier, if their positions coincide.

A Sprite also has a Group property, whose meaning will be made clear in connection with collisions, later in this section.

Sprite images are drawn transparently against the background, in accordance with the basic rule of Picture transparency, where rgb(255,255,255) is the transparent color ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required