Sprite2D

Represents a sprite in the Kray game engine.

Constructors

Link copied to clipboard
constructor(raw: Texture2D)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open val area: Int

The area of the object's bounding box, based on its size parameters.

Link copied to clipboard

The x-component of the 2D acceleration of the Positionable2D object.

Link copied to clipboard

The y-component of the 2D acceleration of the Positionable2D object.

Link copied to clipboard
open override var collideable: Boolean

Whether the sprite can collide with other sprites. False means it cannot.

Link copied to clipboard

A set of all 2D sprites that are currently colliding with this sprite. Uses spatial hashing for O(n) average case complexity.

Link copied to clipboard
open override val costumes: ERROR CLASS: Unresolved name: mutableListOf

An immutable list of all costumes (textures) associated with this sprite.

Link copied to clipboard

The current costume that the sprite is wearing.

Link copied to clipboard
open override var currentCostumeIndex: Int

The index of the current costume being used by this sprite.

Link copied to clipboard

The friction coefficient of the Positionable object. This is used in physics calculations to determine the frictional force acting on the object. The default value is defaultFrictionCoefficient.

Link copied to clipboard
open override val height: Int

The height of the object.

Link copied to clipboard
open override var hitbox: Hitbox2D

The hitbox of the object.

Link copied to clipboard
open override val id: ERROR CLASS: Symbol not found for Uuid

The ID of the sprite.

Link copied to clipboard

A set of all 2D sprites that are currently inside its boundaries.

Link copied to clipboard

Checks if the sprite is currently being clicked by any mouse button.

Link copied to clipboard

Checks if any mouse button is currently being pressed on the sprite.

Link copied to clipboard
open override var isDrawn: Boolean

Whether the sprite has been drawn to the canvas this frame.

Link copied to clipboard

Checks if the sprite is currently being clicked by the mouse.

Link copied to clipboard

Checks if the sprite is currently being middle-clicked by the mouse.

Link copied to clipboard

Checks if the sprite is currently being hovered over by the mouse.

Link copied to clipboard

Checks if the sprite is currently being right-clicked by the mouse.

Link copied to clipboard

The mass multiplier of the Positionable object. This is used in physics calculations to determine the effective mass of the object. The default value is 1.0.

Link copied to clipboard
open val perimeter: Int

The perimeter of the object's bounding box, based on its size parameters.

Link copied to clipboard
open val position: ERROR CLASS: Symbol not found for Pair<kotlin/Float, kotlin/Float>

The position of the object.

Link copied to clipboard

The restitution coefficient of the Positionable object. This is used in physics calculations to determine how bouncy the object is after collisions. The default value is defaultRestitutionCoefficient.

Link copied to clipboard
open override var rotation: Float

The rotation angle of the object in degrees.

Link copied to clipboard
open override var scale: Float

The scale of the object.

Link copied to clipboard

The spin factor of the Positionable object.

Link copied to clipboard
open override var static: Boolean

Whether the sprite is not affected by physics. True means it is not.

Link copied to clipboard

The target rotation steps to move toward then on the ground.

Link copied to clipboard

The x-component of the 2D velocity of the Positionable2D object.

Link copied to clipboard

The y-component of the 2D velocity of the Positionable2D object

Link copied to clipboard
open override val width: Int

The width of the object.

Link copied to clipboard
open override var x: Float

The x-coordinate of the object.

Link copied to clipboard
open override var y: Float

The x-coordinate of the object.

Link copied to clipboard
var zIndex: Int

The z-index of the sprite. Higher values are drawn on top of lower values.

Functions

Link copied to clipboard
open fun addCostume(costume: Texture2D)

Adds a costume to this sprite.

Link copied to clipboard

Aligns the object to the left side of the screen.

Aligns the object to the left side of the target object.

Link copied to clipboard

Aligns the object to the top side of the screen.

Aligns the object to the right side of the target object.

Link copied to clipboard

Aligns the object to the bottom side of the screen.

Aligns the object to the bottom side of the target object.

Link copied to clipboard

Aligns the object to the top side of the screen.

Aligns the object to the top side of the target object.

Link copied to clipboard
open override fun changeTo(index: Int)

Changes the current costume of this sprite to the one at the specified index.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun isAbove(y: Float): Boolean

Returns whether the sprite is above the given Y boundary.

Link copied to clipboard
open override fun isBelow(y: Float): Boolean

Returns whether the sprite is below the given Y boundary.

Link copied to clipboard
open override fun isLeft(x: Float): Boolean

Returns whether the sprite is left of the given X boundary.

Link copied to clipboard
open override fun isRight(x: Float): Boolean

Returns whether the sprite is right of the given X boundary.

Link copied to clipboard
fun Sprite2D.lerpSpin(degrees: Float)

Adds spin to a sprite that will be applied gradually over multiple frames.

Link copied to clipboard
open fun moveBy(deltaX: Float, deltaY: Float)

Moves the object by the specified deltaX and deltaY offsets in place.

Link copied to clipboard
fun Sprite2D.moveDownKey(key: Key, speed: Double = 1.0)

Moves the sprite down when the given key is pressed.

Link copied to clipboard
fun Sprite2D.moveLeftKey(key: Key, speed: Double = 1.0)

Moves the sprite left when the given key is pressed.

Link copied to clipboard
fun Sprite2D.moveRightKey(key: Key, speed: Double = 1.0)

Moves the sprite left when the given key is pressed.

Link copied to clipboard
open fun moveTo(newX: Float, newY: Float)

Moves the object to the specified newX and newY coordinates in place.

Link copied to clipboard
fun Sprite2D.moveUpKey(key: Key, speed: Double = 1.0)

Moves the sprite up when the given key is pressed.

Link copied to clipboard
open override fun nextCostume()

Changes the current costume of this sprite to the next one in the list. Loops back to the first costume if currently at the last one.

Link copied to clipboard
suspend fun Sprite2D.onClick(action: suspend Kray.() -> Unit)

Performs the given action if the sprite is being clicked by any mouse button.

Link copied to clipboard
suspend fun Sprite2D.onDown(action: suspend Kray.() -> Unit)

Performs the given action if the sprite is being clicked by any mouse button.

Link copied to clipboard
open override fun previousCostume()

Changes the current costume of this sprite to the previous one in the list. Loops back to the last costume if currently at the first one.

Link copied to clipboard
open fun removeCostume(costume: Texture2D)

Removes the specified costume from this sprite.

Link copied to clipboard
open fun removeCostumeAt(index: Int)

Removes the costume at the specified index from this sprite.

Link copied to clipboard
open override fun resize(newWidth: Int, newHeight: Int): Sprite2D

Resizes the object to the specified newWidth and newHeight in place.

Link copied to clipboard

Sets both the x and y components of the 2D acceleration of the Positionable2D object.

Link copied to clipboard
open fun setCostume(index: Int, costume: Texture2D)

Sets the costume at the specified index for this sprite.

Link copied to clipboard
open fun setCostumes(vararg list: Texture2D)
open fun setCostumes(list: Iterable<Texture2D>)

Sets the costumes for this sprite.

Link copied to clipboard
open override fun setCurrentCostume(costume: Texture2D)

Sets the current costume of this sprite to the specified image. If the image is not already a costume of this sprite, it is added.

Link copied to clipboard

Sets both the x and y components of the 2D velocity of the Positionable2D object.

Link copied to clipboard
open override fun spin(degrees: Float)

Rotates the object by the specified degrees in place.

Link copied to clipboard
open override fun switchTo(costume: Texture2D)

Changes the current costume of this sprite to the specified image. The costume must already be part of this sprite's costumes.