Skip to main content

@palco-2d/core / SVGImageEntity

Class: SVGImageEntity

Defined in: src/SVGImageEntity/SVGImageEntity.ts:14

BaseEntity serves as the foundational class for all entities managed by the rendering and mouse handling systems. It encapsulates the essential properties and methods shared across all entities, ensuring seamless integration with rendering and interactive functionalities. Any custom entity should extend this class to be properly managed by the engine, maintaining consistency in interactivity and rendering behavior

Extends

Constructors

new SVGImageEntity()

new SVGImageEntity(props): SVGImageEntity

Defined in: src/SVGImageEntity/SVGImageEntity.ts:37

Parameters

props

SVGImageProps

Returns

SVGImageEntity

Overrides

BaseEntity.constructor

Properties

children

children: Map<number, Map<string, BaseEntity>>

Defined in: src/BaseEntity.ts:162

A map representing the children organized by layers.

[
[layer]: [
[id]: BaseEntity
]
]

Inherited from

BaseEntity.children


coords

coords: Coords

Defined in: src/BaseEntity.ts:103

The coordinates of the entity in the canvas. represents the for corners of the entity in the canvas, and the bounding box of that these corners describes.

Inherited from

BaseEntity.coords


globalCompositeOperation

globalCompositeOperation: GlobalCompositeOperation = "source-over"

Defined in: src/BaseEntity.ts:222

The globalCompositeOperation property sets the type of compositing operation to apply when drawing the render method. The default value is source-over.

Inherited from

BaseEntity.globalCompositeOperation


id

id: string

Defined in: src/BaseEntity.ts:35

The unique id of the entity.

Inherited from

BaseEntity.id


isMouseHover

isMouseHover: boolean

Defined in: src/BaseEntity.ts:141

If the mouse is hovering the entity it returns true, otherwise false.

Inherited from

BaseEntity.isMouseHover


isUI

isUI: boolean = false

Defined in: src/BaseEntity.ts:216

When isUI is set to true the entity will be render in the upper canvas, when the mouse detection will preoritize the UI entities over others.

Inherited from

BaseEntity.isUI


layer

layer: number

Defined in: src/BaseEntity.ts:150

The layer of the entity represents the order the render handler will render the entity. 0 is the first layer, and the entities with higher layers will be rendered on top of the entities with lower layers. The layer is relative to the parent, so if the entity is a child, the layer is relative to the parent. If the entity has a layer equal to 0, and the parent has a layer equal to 10, any entity with layer less than 10, that's not a child of a parent, will be rendered before.

Inherited from

BaseEntity.layer


mask

mask: Mask

Defined in: src/BaseEntity.ts:174

Mask Handler to handle the masking of the entity.

Inherited from

BaseEntity.mask


matrix

matrix: number[][] = []

Defined in: src/BaseEntity.ts:116

The matrix of the entity, used to calculate the transformation of the entity.

Inherited from

BaseEntity.matrix


onEntityEvent

onEntityEvent: EntityEvents

Defined in: src/BaseEntity.ts:169

A record of events that the entity has subscribed to. Mouse handler will trigger these events depending on the interaction with the entity. if the entity is static, the mouse handler will not trigger any event.

Inherited from

BaseEntity.onEntityEvent


quadrant

quadrant: EntityQuadrant

Defined in: src/BaseEntity.ts:233

The canvas is divided into quadrants, and each entity is assigned to a quadrant. these quadrants are used to optimize the mouse detection over the entities, preventing the mouse checking for all entities in the canvas, it will only check for the ones within the same quadrant as the mouse. quadrant represents all the quadrants the entity is assigned, depending on the transformation of the entity, it can have assigned multiple quadrants. The quadrant updated when the entity matrix changes.

Inherited from

BaseEntity.quadrant


svgData

svgData: SVGData[] = []

Defined in: src/SVGImageEntity/SVGImageEntity.ts:25

This array contains the SVG data of the asset, it is used for rendering the SVGImageEntity. In case the svg elements are unfolded any changes made to the individual Path2DEntity will be refeclted this value when folded back into the SVGImageEntity.

Accessors

parent

Get Signature

get parent(): BaseEntity

Defined in: src/BaseEntity.ts:197

Returns

BaseEntity

Set Signature

set parent(parent): void

Defined in: src/BaseEntity.ts:201

Parameters
parent

BaseEntity

Returns

void

Inherited from

BaseEntity.parent


position

Get Signature

get position(): Vec2

Defined in: src/BaseEntity.ts:45

The position of the entity in the canvas, relative to the top-left corner. if the entity is a child, the position is relative to the parent.

Returns

Vec2

Set Signature

set position(position): void

Defined in: src/BaseEntity.ts:49

Parameters
position

Vec2

Returns

void

Inherited from

BaseEntity.position


realSize

Get Signature

get realSize(): Vec2

Defined in: src/BaseEntity.ts:94

The size of the element property (not considering canvas transformation)

Returns

Vec2

Vec2

Inherited from

BaseEntity.realSize


rotation

Get Signature

get rotation(): number

Defined in: src/BaseEntity.ts:124

Returns

number

Set Signature

set rotation(rotation): void

Defined in: src/BaseEntity.ts:128

Parameters
rotation

number

Returns

void

Inherited from

BaseEntity.rotation


size

Get Signature

get size(): Vec2

Defined in: src/BaseEntity.ts:67

The size of the entity in the canvas. if the entity is a child, the size is relative to the parent.

Returns

Vec2

Set Signature

set size(size): void

Defined in: src/BaseEntity.ts:75

Parameters
size

Vec2

Returns

void

Inherited from

BaseEntity.size


useAsMask

Get Signature

get useAsMask(): boolean

Defined in: src/BaseEntity.ts:180

When set to true children elements will be masked Note: When using and element as a mask globalCompositeOperation does not take effect

Returns

boolean

Set Signature

set useAsMask(enable): void

Defined in: src/BaseEntity.ts:184

Parameters
enable

boolean

Returns

void

Inherited from

BaseEntity.useAsMask

Methods

addChild()

addChild(child): void

Defined in: src/BaseEntity.ts:475

Parameters

child

BaseEntity

Returns

void

Inherited from

BaseEntity.addChild


destroy()

destroy(): void

Defined in: src/BaseEntity.ts:504

Returns

void

Inherited from

BaseEntity.destroy


fold()

fold(): void

Defined in: src/SVGImageEntity/SVGImageEntity.ts:125

Parses each Path2DEntity into a CachedSVGAsset with the updated values,

and then removes the Path2DEntity from the children of SVGImageEntity.

Returns

void


getCoords()

protected getCoords(): Coords

Defined in: src/BaseEntity.ts:354

Gets the coords of the entity in the canvas. the coords are the corners of the entity in the canvas. eg: top-left, top-right, bottom-right, bottom-left

Returns

Coords

Inherited from

BaseEntity.getCoords


getIdAddress()

getIdAddress(): string

Defined in: src/BaseEntity.ts:604

Get the string address of the entity. With the address id you can get any entity in the scene, it represents the path to the entity.

Returns

string

Example

{layer}:{id}/{layer}:{id}/{layer}:{id}

the first layer and id is the entity itself, the next layers and ids are the parents of the entity.

Inherited from

BaseEntity.getIdAddress


getMatrix()

protected getMatrix(): number[][]

Defined in: src/BaseEntity.ts:337

Gets the transformation matrix of the entity,

Returns

number[][]

Inherited from

BaseEntity.getMatrix


getOwnAddress()

getOwnAddress(): string

Defined in: src/BaseEntity.ts:614

Returns

string

Inherited from

BaseEntity.getOwnAddress


getPivotPosition()

getPivotPosition(): object

Defined in: src/BaseEntity.ts:293

Returns

object

x

x: number

y

y: number

Inherited from

BaseEntity.getPivotPosition


getRelativePosition()

getRelativePosition(mousePosition, relativeToParent?): object

Defined in: src/BaseEntity.ts:419

Parameters

mousePosition

Vec2

relativeToParent?

boolean

Returns

object

x

x: number

y

y: number

Inherited from

BaseEntity.getRelativePosition


getScale()

getScale(): object

Defined in: src/BaseEntity.ts:279

Returns

object

x

x: number = 1

y

y: number = 1

Inherited from

BaseEntity.getScale


getStatic()

getStatic(): boolean

Defined in: src/BaseEntity.ts:623

Returns

boolean

Inherited from

BaseEntity.getStatic


getWorldMatrix()

getWorldMatrix(): number[][]

Defined in: src/BaseEntity.ts:317

Returns

number[][]

Inherited from

BaseEntity.getWorldMatrix


isFolded()

isFolded(): boolean

Defined in: src/SVGImageEntity/SVGImageEntity.ts:179

Returns true if the SVGImageEntity is folded, false otherwise.

Returns

boolean


isObjectInViewport()

isObjectInViewport(viewport): boolean

Defined in: src/BaseEntity.ts:550

Parameters

viewport
position

Vec2

size

Vec2

Returns

boolean

Inherited from

BaseEntity.isObjectInViewport


isPointOverEntity()

isPointOverEntity(point): boolean

Defined in: src/SVGImageEntity/SVGImageEntity.ts:68

Checks if the point is over the SVGImageEntity. if SVGImageEntity is unfolded, it will return false, so the children Path2DEntity can be clicked on

Parameters

point

Vec2

Returns

boolean

Overrides

BaseEntity.isPointOverEntity


on()

on(event, callback): void

Defined in: src/BaseEntity.ts:274

Parameters

event

EventsType

callback

() => void

Returns

void

Inherited from

BaseEntity.on


removeChild()

removeChild(address): void

Defined in: src/BaseEntity.ts:492

Parameters

address

string

Returns

void

Inherited from

BaseEntity.removeChild


render()

render(ctx): void

Defined in: src/SVGImageEntity/SVGImageEntity.ts:183

Parameters

ctx

CanvasRenderingContext2D

Returns

void

Overrides

BaseEntity.render


serialize()

serialize(): SerializedBaseEntityProps

Defined in: src/BaseEntity.ts:573

Returns

SerializedBaseEntityProps

Inherited from

BaseEntity.serialize


setStatic()

setStatic(staticValue): void

Defined in: src/BaseEntity.ts:618

Parameters

staticValue

boolean

Returns

void

Inherited from

BaseEntity.setStatic


unfold()

unfold(): void

Defined in: src/SVGImageEntity/SVGImageEntity.ts:103

Creates a Path2DEntity for each path in the SVG asset and adds it as a child of SVGImageEntity, doing so each element of the SVG can be manipulated individually.

Returns

void


updateBoundingBox()

updateBoundingBox(): void

Defined in: src/SVGImageEntity/SVGImageEntity.ts:79

Updates the bounding box of the SVGImageEntity based on the current SVGData.

  • BaseEntity

Returns

void