## Constructors

- [Animation](/content/docs/Animation/index.html)
- [IsoCharacter](/content/docs/IsoCharacter/index.html)
- [Path](/content/docs/Path/index.html)
- [PhysicsObject](/content/docs/PhysicsObject/index.html)
- [SceneObject](/content/docs/SceneObject/index.html)
- [SceneObjectGroup](/content/docs/SceneObjectGroup/index.html)
- [Sprite](/content/docs/Sprite/index.html)
- [TextSprite](/content/docs/TextSprite/index.html)
- [TilemapCharacter](/content/docs/TilemapCharacter/index.html)
- [wade](/content/docs/wade/index.html)
- [wade.drawFunctions](/content/docs/wade.drawFunctions)
- [wade.iso](/content/docs/wade.iso)
- [wade.physics](/content/docs/wade.physics)
- [wade.tilemap](/content/docs/wade.tilemap)
- [wade.vec2](/content/docs/wade.vec2)

## Sprite

# Constructor Summary

**Sprite**

A Sprite object is used to display images. It may have references to Animation objects if the image to display is supposed to be animating.

# Functions Summary

**Sprite.addAnimation** _(name, animation, dontPlay)_

Add an animation to the sprite. If, after this operation, there is only one animation for this sprite, it will be played automatically

**Sprite.alwaysDraw** _(toggle)_

Force a sprite to get drawn every frame, disabling potential optimizations. This does not happen by default, i.e. drawing optimizations are enabled by default.

**Sprite.bringToFront** _()_

Bring the sprite to the front of its layer. Note that if any sorting function (other than 'none') has been specified for the layer, when the sorting occurs it will override this operation

**Sprite.cache** _()_

Draw this sprite to an off-screen canvas, then use this canvas as a source image whenever this sprite needs to be drawn again

**Sprite.clone** _()_

Clone the sprite

**Sprite.containsScreenPoint** _(point)_

Check whether the sprite contains a given screen space point

**Sprite.drawToImage** _(virtualPath, replace, offset, transform, compositeOperation, renderMode)_

Draw a sprite to an image associated with a virtual path. The image will be stored in CPU memory. To create a WebGL texture in GPU memory, use Sprite.drawToTexture instead.

**Sprite.drawToTexture** _(gpuTextureName, cpuTextureName)_

Draw the sprite to a WebGL texture in GPU memory. Note that this is only possible if the sprite is currently on a WebGL layer.

**Sprite.fadeIn** _(time, callback)_

Fade in effect, gradually changing the opacity (alpha) of the sprite from 0 to 1. If the sprite is invisible, it is set to visible before fading in.

**Sprite.fadeOut** _(time, callback)_

Fade out effect, gradually changing the opacity (alpha) of the sprite from 1 to 0. After fading out, the sprite is set to invisible.

**Sprite.getAllImageNames** _()_

Get the names of all images being used by this sprite and its animations

**Sprite.getAlphaThreshold** _()_

Check whether the Sprite is using pixel-perfect mouse events, i.e. whether it discards mouse events on transparent pixels

**Sprite.getAnimation** _(name)_

Get the animation object associated with a given animation name

**Sprite.getCurrentAnimation** _()_

Get the active animation object for the sprite

**Sprite.getCurrentAnimationName** _()_

Get the name of the active animation for the sprite

**Sprite.getDrawFunction** _()_

Get the current draw function of the sprite

**Sprite.getDrawModifiers** _()_

Get the current modifiers that are applied to the sprite

**Sprite.getImageArea** _()_

Get the area of the source image (expressed as a fraction of the source image size) that is being used to draw this sprite. If this wasn't modified with setImageArea(), by default the sprite uses the full image from (0, 0) to (1, 1).

**Sprite.getImageName** _()_

Get the name of the image being used

**Sprite.getIndexInLayer** _()_

Get the index of the sprite in its layer. For unsorted layers this matches the order in which the sprites were added to the layers, though for layers with sorting this may change every frame accoring to the sorting criterion.

**Sprite.getLayerId** _()_

Get the id of the sprite's layer

**Sprite.getName** _()_

Get the current name of this sprite, if it was set with Sprite.setName()

**Sprite.getOverlappingObjects** _(searchAllLayers, precision)_

Get an array of objects overlapping this sprite

**Sprite.getPixelShader** _()_

Get the source code of the current pixel shader function for this sprite

**Sprite.getPixelShaderUniforms** _()_

Get a list of the custom shader uniforms for this sprite.

**Sprite.getPosition** _()_

Get the world space position of the sprite

**Sprite.getRotation** _()_

Get the current rotation angle of the sprite

**Sprite.getScaleFactor** _()_

Get the current scale factor of the sprite, that is its size compared to the source image (or animation frame) size

**Sprite.getSceneObject** _()_

Get the parent scene object for this sprite (if any)

**Sprite.getScreenBoundingBox** _()_

Get the bounding box of the Sprite in screen space

**Sprite.getScreenPositionAndExtents** _()_

Get the screen space position and extents for this sprite

**Sprite.getSize** _()_

Get the world space size of the sprite

**Sprite.getSortPoint** _()_

Get the sprite's sort point that is used in the calculations to determine whether the sprite should appear in front of other sprites in the same layer, according to the layer's sorting mode.

**Sprite.getWorldOffset** _(screenPosition)_

Convert a screen space position into a world space offset relative to the sprite's world space position

**Sprite.hasAnimation** _(name)_

Check whether the sprite has an animation that matches the given name

**Sprite.isAlwaysDrawing** _()_

Check whether a sprite is being forcefully drawn every frame

**Sprite.isOnScreen** _()_

Check whether the Sprite is currently visible on the screen

**Sprite.isUsingPixelPerfectMouseEvents** _()_

Check whether the Sprite is using pixel-perfect mouse events, i.e. whether it discards mouse events on transparent pixels

**Sprite.isVisible** _()_

Check whether the sprite is visible

**Sprite.overlapsSprite** _(otherSprite, precision)_

Test to see whether this sprite overlaps another sprite

**Sprite.playAnimation** _(name, direction)_

Play an animation for this sprite

**Sprite.pushToBack** _()_

Send the sprite to the back of its layer. Note that if any sorting function (other than 'none') has been specified for the layer, when the sorting occurs it will override this operation

**Sprite.putBehindSprite** _(otherSprite)_

Move the sprite behind another sprite in the same layer. Note that if any sorting function (other than 'none') has been specified for the layer, when the sorting occurs it will override this operation

**Sprite.resumeAnimation** _()_

Resume playing an animation that had been stopped

**Sprite.serialize** _(stringify, propertiesToExclude)_

Export this sprite to an object that can then be used to create a new sprite like this one (by passing the resulting object to the Sprite constructor).

**Sprite.setDirtyArea** _()_

Mark the area occupied by the sprite as dirty. Depending on the sprite's layer's properties, this operation may cause this and some other sprites to be redrawn for the next frame

**Sprite.setDrawFunction** _(drawFunction)_

Set a custom draw function for the sprite

**Sprite.setDrawModifiers** _(modifiers)_

Set draw modifiers for this sprite.

**Sprite.setImageArea** _(minX, minY, maxX, maxY)_

Set the area of the source image that should be used to draw this sprite. Numbers should be between 0 and 1, representing a fraction of the source image size.

**Sprite.setImageFile** _(image, updateSizeFromImage)_

Set an image to use with the current sprite

**Sprite.setIndexInLayer** _(index)_

Set the sprite's index in its layer.

**Sprite.setLayer** _(layerId)_

Set a new layer for the sprite

**Sprite.setName** _(name)_

Set a name for the sprite

**Sprite.setPixelShader** _(shaderSource, shaderUniforms)_

Set a custom pixel shader for this sprite.

**Sprite.setPosition** _(positionX, positionY)_

Set the world space position of the sprite.

**Sprite.setRotation** _(rotation)_

Set a rotation angle for the sprite

**Sprite.setSceneObject** _(sceneObject)_

Set the parent scene object for the sprite.

**Sprite.setSize** _(width, height, resetScaleFactor)_

Set the world space size of the sprite

**Sprite.setSortPoint** _(x, y)_

Set a sort point for the sprite. This will be used in the calculations to determine whether the sprite should appear in front of other sprites in the same layer, according to the layer's sorting mode.

**Sprite.setVisible** _(toggle)_

Show or hide a sprite

**Sprite.step** _()_

Perform a simulation step for the sprite. This involves updating the sprite's animation, if there is one that is currently playing.

**Sprite.stopAnimation** _()_

Stop the animation that is currently playing

**Sprite.usePixelPerfectMouseEvents** _(threshold)_

Set the Sprite to use (or not use) pixel-perfect mouse events, i.e. discard mouse events on transparent pixels. By default, Sprites do not use pixel-perfect mouse events. Enabling this has implications for performance and memory usage.
