The
Sprite object is an animatable image that appears in the game. It is one of the most important objects for most Construct 2 games. It is used to make most visual elements in a game, such as the player, enemies, projectiles, explosions and non-tiling scenery (tiled scenery is much better done with the
Tiled Background object).
If a Sprite has a single animation with a single frame, it simply shows an image without animating. However, multiple animations can be added to Sprite objects with the
Image and Animations editor.
All
instances of Sprite objects share their animations. In other words, there is a single set of images comprising the animations which belongs to the
object type, and these images are referenced by instances.
Sprite properties
AnimationsClick the
Edit link to open the
Image and Animations editor for the object. All instances of the object type share a single set of animations.
SizeClick the
Make 1:1 link to size the selection at original size (100%). This makes the width and height of the object the same as its first animation frame image.
Initial visibilitySet whether the object is shown (visible) or hidden (invisible) when the layout starts.
Initial frameSet the initially displaying animation frame from the object's first animation. This is a zero-based index, so the first frame is 0. This can be useful for storing different tiles or scenery in different animation frames of a single Sprite object type.
EffectChoose a blend mode for the object.
(none) means the object displays normally over the background. Effects like explosions and lighting effects can be achieved with these blend modes. A demo of all the effects can be found
here, or see the
Sprite effects.capx project in the Examples folder in Construct 2's install directory.
Sprite conditions
For conditions in common to other objects, see
Common conditions.
Compare frameCompare the current animation frame number, which is a zero-based index (the first frame is 0).
Is flippedIs mirroredTrue if the object has been flipped or mirrored with the
Set flipped or
Set mirrored actions.
Is playingTrue if a given animation is currently set. Animations are identified by their name (case insensitive).
On any finishedTriggered when any animation reaches the end. Looping animations do not finish.
On finishedTriggered when a given animation reaches the end. Looping animations do not finish. Animations are identified by their name (case insensitive).
On frame changedTriggered whenever the animation switches to another frame while the animation is playing.
Is overlapping another objectIs overlapping at offsetTrue if any instance is overlapping any instance of another object. The collision polygons are taken in to account if set, as well as the object's size and rotation. The 'offset' variant will test for an overlap at an offset from the first object. For example, testing for an overlap at an offset of (100, 0) will temporarily move the object to the right 100 pixels, test for the overlap, then move it back again.
On collision with another objectTriggered upon the first time any instance starts overlapping any instance of another object. The collision polygons are taken in to account if set, as well as the object's size and rotation.
Sprite actions
For actions common to other objects, see
Common actions.
Set animationChange the currently playing animation to another animation. Animations are identified by their name (case insensitive). The new animation can either play from the
beginning or from the same frame number as the last animation was on (
current frame).
Set flippedSet whether the object image appears vertically flipped or normal. This also affects image points and the collision polygon.
Set mirroredSet whether the object image appears horizontally mirrored or normal. This is useful for platform games. Mirroring also affects image points and the collision polygon.
Set frameSet the current zero-based animation frame number that is showing. The animation will continue to play at its current speed.
Set speedSet the playback rate of the current animation, in animation frames per second. Instances can have different animation speeds.
StartIf the current animation is stopped, start playing the animation again. Playback can either resume from the
current frame, or restart from the
beginning.
StopStop the current animation from playing. The object will be left showing the current animation frame.
Spawn another objectCreate a new instance of a given object type. The new instance is created at the current object's position and also set to the same angle. The created object can be on any layer (chosen by its name or its zero-based number), and it can be positioned by an
image point instead of the object's origin (chosen by its name or number). If a Family is created, a random object type in the family is picked.
Set scaleSets the width and height to a multiple of the object's original size, similar to zooming the object proportionally. For example, if the object is 50x100,
Set scale to 2 will set its size to 100x200, and
Set scale to 0.1 will set its size to 5x10.
Sprite expressions
For expressions common to other objects, see
common expressions.
AnimationFrameThe currently displaying zero-based animation frame number.
AnimationFrameCountThe number of animation frames in the current animation.
AnimationNameA string containing the name of the currently playing animation.
AnimationSpeedThe current playback rate of the current animation, in animation frames per second.
ImageWidthImageHeightThe original dimensions of the object (its current animation frame image size), in pixels. Since objects can be stretched at runtime causing the normal
Width and
Height expressions to return different values, these can be used to get the original size regardless of the stretched size.