Object

Sprite Class

A picture that can be animated by a SpriteSurface control.

Properties
Group
Image
Priority
ScreenX
ScreenY
X
Y

Methods
Close

# Notes

A Sprite object is a picture that can be animated using a SpriteSurface control. Moving the Sprite across the screen is simply a matter of changing the Sprite's x and y properties in the NextFrame event handler of the SpriteSurface control that created the sprite. Should two sprites touch each other during the animation, there is the potential for a collision. A collision means that the SpriteSurface's Collision event handler will be executed and the two Sprites that have collided will be passed to it. This gives you the opportunity to decide what should happen when the two sprites come into contact. Whether or not a collision occurs is based on the values of the two Sprites' Group properties:

Group Values | Collision?
--- | ---
0 for either Sprite | No
Both Sprites have same positive value | No
Both Sprites have different positive values | Yes
One Sprite has a negative value | Yes

Sprites are drawn during the SpriteSurface NextFrame event handler's execution in order based on their Priority property. This property is assigned by default based on the order the Sprites were created. The first Sprite's Priority is 1, the second Sprite's Priority is 2, etc. In this example, when the first and second Sprites pass over each other, the second Sprite will appear to be in front of the first Sprite.

All Sprite object properties are changeable at runtime. This means you can change the Sprite's image, location, group, and priority during the animation.

A Sprite can be created using the New operator and attached to a SpriteSurface using the Attach method of the SpriteSurface class.

Comparing ScreenX and X (and ScreenY and Y)

ScreenX and X (and ScreenY and Y) will be the same for a SpriteSurface that has not been scrolled. When it is scrolled, the sprite's ScreenX and ScreenY values change because their positions on the screen have changed. Their X and Y values remain the same because their position in "world" coordinates has not changed.

## Mask and Transparency Properties

Sprites ignore the Mask property of the Picture, as well as the value of the Transparent property. White pixels are always transparent and non-white pixels are always opaque.

# Examples

See the SpriteSurface control's example.

# See Also

SpriteSurface control.