The Sprite class represents a sprite, or an on-screen graphical object. Sprites render themselves to their host SpriteApp's back-buffer image. Historically, sprites have represented 2D objects or bitmaps which move on screen; however, this object may also do special effects or image processing.
agent |
- ( id ) agent;
Returns the sprite's agent. An agent is a delegate whose step method is called on every frame update. This can be used to override sprite behavior without overriding the sprite class (such as with scripting). If the agent has no step method, it is ignored.
frame |
- ( unsigned int ) frame;
Returns the number of the current frame.
goBehind: |
- ( void ) goBehind: (Sprite *) s;
Instructs the sprite to move behind the sprite s. Of course it only sends -place:behind: to the sprite's host SpriteApp.
height |
- ( unsigned int ) height;
Returns the sprite's height as an integer.
host |
- ( SpriteApp *) host;
Returns the host SpriteApp of which thsi sprite is a client.
hotspot |
- ( svec2 ) hotspot;
Returns the sprite's hotspot as an svec2. The hotspot is a point relative to the upper-left corner of the sprite (default is (0,0)). Calls to -moveTo: will center the hotspot over the location passed to that method.
initOn:shape:frames: |
- ( id ) initOn: (SpriteApp *) h shape: (SpriteImage *) si frames: (unsigned int ) mf;
Initialises the sprite on host h, with shape si (which can be NULL for an "invisible" sprite, and max frames mf. The image si is divided vertically into mf frames, and the sprite will assume one of these frame-shapes at a time.
isTouching: |
- ( int ) isTouching: (Sprite *) s;
Returns a Boolean value corresponding to whether the sprite's bounding rectangle overlaps with that of another sprite. Useful for simple collision detection.
moveTo: |
- ( void ) moveTo: (svec2 ) p;
Moves the sprite to the coordinates specified in the svec2 struct given as p. The sprite's hotspot will be centered over the point p.
next |
- ( Sprite *) next;
Returns the next sprite after this one in the sprite list.
pos |
- ( svec2 ) pos;
Returns the sprite's position as an svec2.
prev |
- ( Sprite *) prev;
Returns the previous sprite in the sprite list.
renderOn: |
- ( void ) renderOn: (SpriteImage *) anImage;
Draws the sprite on anImage. May be overrided.
setAgent: |
- ( void ) setAgent: (id ) a;
Sets the sprite's agent to the object pointed to by a.
setFrame: |
- ( void ) setFrame: (unsigned int ) f;
Changes the current frame number to f. The frame count cannot exceed the maximum number of frames for the image; it will have a modulus operation applied so that it doesn't (i.e., a frame number of 30 on a 4-frame image will be the same as a frame number of 2).
setHost: |
- ( SpriteApp *) setHost: (SpriteApp *) t;
Sets the host SpriteApp for this sprite to t. Used only by SpriteApp. Don't use it!
setHotspot: |
- ( void ) setHotspot: (svec2 ) p;
Sets the sprite's hotspot to the x and y values given by p. The hotspot is a point relative to the upper-left corner of the sprite (default is (0,0)). Calls to -moveTo: will center the hotspot over the location passed to that method.
setNext: |
- ( Sprite *) setNext: (Sprite *) t;
Sets the next sprite in the list to the sprite t. Used only by SpriteApp methods to maintain the list. Don't use it yourself!
setPrev: |
- ( Sprite *) setPrev: (Sprite *) t;
Sets the previous sprite in the list to the sprite t. Used only by SpriteApp methods to maintain the list. Don't use it yourself!
setShape: |
- ( SpriteImage *) setShape: (SpriteImage *) sh;
Sets the sprite's shape to sh with only one frame.
setShape:frames: |
- ( SpriteImage *) setShape: (SpriteImage *) sh frames: (unsigned int ) f;
Sets the sprite's shape to sh, with a frame count of f. The image sh is divided vertically into f frames (so its height should be f times the height of a single frame).
setVel: |
- ( void ) setVel: (svec2 ) v;
Sets the sprite's velocity to the x and y values given by v. Velocity values are in pixels per fiftieth of a second.
shape |
- ( SpriteImage *) shape;
Returns a pointer to the SpriteImage which represents this sprite's shape.
size |
- ( svec2 ) size;
Returns the sprite's size as an svec2.
step |
- ( void ) step;
This method is called once per frame update by the host SpriteApp. Typically it updates the sprite's position. You can override it to make it do anything, however: check for collisions, switch frames in a multi-frame animation, etc.
vel |
- ( svec2 ) vel;
Returns the sprite's velocity (in pixels per fiftieth of a second) as an svec2.
width |
- ( unsigned int ) width;
Returns the sprite's width as an integer.
(Last Updated 7/27/2005)