Util
Index
Namespaces
Enumerations
Classes
Interfaces
Type Aliases
Functions
Namespaces
DrawUtil
BorderRadius
bl
Bottom-left
br
Bottom-right
tl
Top-left
tr
Top-right
LineCapStyle
A canvas linecap style. "butt" is the default flush style, "round" is a semi-circle cap with a radius half the width of the line, and "square" is a rectangle that is an equal width and half height cap.
circle
line
Draw a line on canvas context
Parameters
ctx: CanvasRenderingContext2D
The canvas context
color: Color = Color.Red
The color of the line
x1: number
The start x coordinate
y1: number
The start y coordinate
x2: number
The ending x coordinate
y2: number
The ending y coordinate
thickness: number = 1
The line thickness
cap: LineCapStyle = 'butt'
The LineCapStyle (butt, round, or square)
Returns void
point
roundRect
Draw a round rectangle on a canvas context
Parameters
ctx: CanvasRenderingContext2D
The canvas context
x: number
The top-left x coordinate
y: number
The top-left y coordinate
width: number
The width of the rectangle
height: number
The height of the rectangle
radius: number | BorderRadius = 5
The border radius of the rectangle
stroke: Color = Color.White
The Color to stroke rectangle with
fill: Color = null
The Color to fill rectangle with
Returns void
vector
Enumerations
LogLevel
Logging level that Excalibur will tag
Debug
Error
Fatal
Info
Warn
Classes
ConsoleAppender
Console appender for browsers (i.e. console.log)
constructor
Returns ConsoleAppender
publiclog
EasingFunctions
Standard easing functions for motion in Excalibur, defined on a domain of [0, duration] and a range from [+startValue,+endValue] Given a time, the function will return a value from positive startValue to positive endValue.
function Linear (t) {
return t * t;
}
// accelerating from zero velocity
function EaseInQuad (t) {
return t * t;
}
// decelerating to zero velocity
function EaseOutQuad (t) {
return t * (2 - t);
}
// acceleration until halfway, then deceleration
function EaseInOutQuad (t) {
return t < .5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
}
// accelerating from zero velocity
function EaseInCubic (t) {
return t * t * t;
}
// decelerating to zero velocity
function EaseOutCubic (t) {
return (--t) * t * t + 1;
}
// acceleration until halfway, then deceleration
function EaseInOutCubic (t) {
return t < .5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
}constructor
Returns EasingFunctions
publicstaticEaseInCubic
publicstaticEaseInOutCubic
publicstaticEaseInOutQuad
publicstaticEaseInQuad
publicstaticEaseOutCubic
publicstaticEaseOutQuad
publicstaticLinear
publicstaticCreateReversibleEasingFunction
Parameters
easing: EasingFunction<number>
Returns EasingFunction<number>
publicstaticCreateVectorEasingFunction
Parameters
easing: EasingFunction<number>
Returns EasingFunction<Vector>
Logger
Static singleton that represents the logging facility for Excalibur. Excalibur comes built-in with a ConsoleAppender and ScreenAppender. Derive from Appender to create your own logging appenders.
constructor
Returns Logger
publicdefaultLevel
Gets or sets the default logging level. Excalibur will only log messages if equal to or above this level. Default: LogLevel.Info
publicaddAppender
publicclearAppenders
Clears all appenders from the logger
Returns void
publicdebug
Writes a log message at the LogLevel.Debug level
Parameters
rest...args: any[]
Accepts any number of arguments
Returns void
publicdebugOnce
Writes a log message once at the LogLevel.Fatal level, if it sees the same args again it wont log
Parameters
rest...args: any[]
Accepts any number of arguments
Returns void
publicerror
Writes a log message at the LogLevel.Error level
Parameters
rest...args: any[]
Accepts any number of arguments
Returns void
publicerrorOnce
Writes a log message once at the LogLevel.Error level, if it sees the same args again it won't log
Parameters
rest...args: any[]
Accepts any number of arguments
Returns void
publicfatal
Writes a log message at the LogLevel.Fatal level
Parameters
rest...args: any[]
Accepts any number of arguments
Returns void
publicfatalOnce
Writes a log message once at the LogLevel.Fatal level, if it sees the same args again it won't log
Parameters
rest...args: any[]
Accepts any number of arguments
Returns void
publicinfo
Writes a log message at the LogLevel.Info level
Parameters
rest...args: any[]
Accepts any number of arguments
Returns void
publicinfoOnce
Writes a log message once at the LogLevel.Info level, if it sees the same args again it wont log
Parameters
rest...args: any[]
Accepts any number of arguments
Returns void
publicwarn
Writes a log message at the LogLevel.Warn level
Parameters
rest...args: any[]
Accepts any number of arguments
Returns void
publicwarnOnce
Writes a log message once at the LogLevel.Warn level, if it sees the same args again it won't log
Parameters
rest...args: any[]
Accepts any number of arguments
Returns void
publicstaticgetInstance
Gets the current static instance of Logger
Returns Logger
Observable
Simple Observable implementation
Type parameters
- T
is the typescript Type that defines the data being observed
constructor
Type parameters
- T
Returns Observable<T>
publicobservers
publicsubscriptions
clear
Removes all observers and callbacks
Returns void
notifyAll
Broadcasts a message to all observers and callbacks
Parameters
message: T
Returns void
register
Register an observer to listen to this observable
Parameters
observer: Observer<T>
Returns void
subscribe
Register a callback to listen to this observable
Parameters
func: (val: T) => any
Returns void
unregister
Remove an observer from the observable
Parameters
observer: Observer<T>
Returns void
unsubscribe
Remove a callback that is listening to this observable
Parameters
func: (val: T) => any
Returns void
ScreenAppender
On-screen (canvas) appender
constructor
Parameters
options: ScreenAppenderOptions
Returns ScreenAppender
publiccanvas
publiclog
Serializer
Central serialization system for ExcaliburJS Handles all serialization/deserialization with extensible registry
constructor
Returns Serializer
staticactorFromJSON
Parameters
json: string
Returns Actor
staticactorToJSON
Parameters
actor: Actor
pretty: boolean = false
Returns string
staticclearComponents
Clear all registered components
Returns void
staticclearCustomActors
Returns void
staticclearGraphics
Clear all registered graphics
Returns void
staticdeserializeActor
Parameters
data: EntityData
Returns Actor
staticdeserializeComponent
Deserialize a component
Parameters
data: ComponentData
Returns Component
staticdeserializeEntity
Parameters
data: EntityData
Returns Entity<any>
staticentityFromJSON
Deserialize entity from JSON string
Parameters
json: string
Returns Entity<any>
staticentityToJSON
Serialize entity to JSON string
Parameters
entity: Entity<any>
pretty: boolean = false
Returns string
staticgetCustomActor
Parameters
typeName: string
Returns typeof Actor
staticgetCustomSerializer
Parameters
typeName: string
Returns { deserialize: (data: any) => any; serialize: (obj: any) => any }
deserialize: (data: any) => any
Parameters
data: any
Returns any
serialize: (obj: any) => any
Parameters
obj: any
Returns any
staticgetGraphic
Parameters
id: string
Returns any
staticgetRegisteredComponents
Get all registered component types
Returns string[]
staticgetRegisteredCustomActors
Returns string[]
staticgetRegisteredGraphics
Get all registered graphic IDs
Returns string[]
staticgetRegistry
Parameters
registry: graphics | actors | components
Returns Map<string, any>
staticinit
Parameters
autoRegisterComponents: boolean = true
Returns void
staticisComponentRegistered
Check if a component type is registered
Parameters
typeName: string
Returns boolean
staticisCustomActorRegistered
Parameters
typeName: string
Returns boolean
staticisGraphicRegistered
Check if a graphic is registered
Parameters
id: string
Returns boolean
staticisInitialized
Returns boolean
staticregisterComponent
Type parameters
- T: Component
Parameters
ctor: ComponentCtor<T>
Returns void
staticregisterComponents
Parameters
ctors: ComponentCtor[]
Returns void
staticregisterCustomActor
Parameters
ctor: typeof Actor
Returns void
staticregisterCustomActors
Parameters
ctors: typeof Actor[]
Returns void
staticregisterCustomSerializer
Register a custom serializer for a specific type Useful for types like Vector, Color, BoundingBox, etc.
Parameters
typeName: string
serialize: (obj: any) => any
deserialize: (data: any) => any
Returns void
staticregisterGraphic
Parameters
id: string
graphic: any
Returns void
staticregisterGraphics
Parameters
graphics: Record<string, any>
Returns void
staticreset
Reset all registrations (useful for testing)
Returns void
staticserializeActor
Parameters
actor: Actor
Returns EntityData
staticserializeComponent
Serialize a component
Parameters
component: Component
Returns ComponentData
staticserializeEntity
Parameters
entity: Entity<any>
Returns EntityData
staticunregisterComponent
Unregister a component type
Parameters
typeName: string
Returns boolean
staticunregisterCustomActor
Parameters
typeName: string
Returns boolean
staticunregisterGraphic
Unregister a graphic
Parameters
id: string
Returns boolean
staticvalidateEntityData
Validate entity data structure
Parameters
data: any
Returns data is EntityData
Interfaces
Appender
Contract for any log appender (such as console/screen)
log
EasingFunction
Parameters
currentTime: number
startValue: TValueToEase
endValue: TValueToEase
duration: number
Returns TValueToEase
Message
Defines a generic message that can contain any data
Type parameters
- T
is the typescript Type of the data
data
type
Observer
Defines an interface for an observer to receive a message via a notify() method
Type parameters
- T
notify
Parameters
message: T
Returns void
ScreenAppenderOptions
optionalcolor
Provide a text color
engine
optionalheight
Optionally set the height of the overlay canvas
optionalwidth
Optionally set the width of the overlay canvas
optionalxPos
Adjust the text offset from the left side of the screen
optionalzIndex
Optionally set the CSS zindex of the overlay canvas
Type Aliases
MaybeObserver
Defines an interface for something that might be an observer if a notify() is present
Type parameters
- T
Functions
addItemToArray
Add an item to an array list if it doesn't already exist. Returns true if added, false if not and already exists in the array.
Type parameters
- T
Parameters
item: T
array: T[]
Returns boolean
contains
See if an array contains something
Parameters
array: any[]
obj: any
Returns boolean
delay
Create a promise that resolves after a certain number of milliseconds
It is strongly recommended you pass the excalibur clock so delays are bound to the excalibur clock which would be unaffected by stop/pause.
Parameters
milliseconds: number
optionalclock: Clock
Returns Promise<void>
fail
Used for exhaustive checks at compile time
Parameters
message: never
Returns never
getMinIndex
Parameters
array: number[]
Returns number
getPosition
Find the screen position of an HTML element
Parameters
el: HTMLElement
Returns Vector
isLegacyEasing
Parameters
optionalx: Function
Returns x is EasingFunction<number>
isObject
Simple object check.
Parameters
item: any
Returns item is object
mergeDeep
Deep merge two objects.
Type parameters
- T: object
Parameters
target: T
rest...sources: T[]
Returns T
omit
Remove keys from object literals
Type parameters
- TObject: Object
- Keys: string | number | symbol
Parameters
object: TObject
keys: Keys[]
Returns Omit<TObject, Keys>
removeItemFromArray
Remove an item from an list
Type parameters
- T
Parameters
item: T
array: T[]
Returns boolean
Represents border radius values