Home Reference Source
public class | source

Picture

Extends:

WorldElement → Picture

The Picture class is used to draw images on the screen. Extra attention must be made when waiting for the image to load.

Constructor Summary

Public Constructor
public

constructor(path: string, opts: object)

Member Summary

Public Members
public

Height of the scaled image in units.

public

Image object where picture will be loaded.

public

Flag for allowing the picture to be dragged around.

public

Flag for when the image has fully loaded.

public

Sets the pivot point around which the picture is drawn.

public

Width of the scaled image in units.

Method Summary

Public Methods
public

Tests if the image is fully loaded.

Private Methods
private

draw()

Main draw function for the picture called by the World automatically.

private

Tests if the mouse is over the picture.

Inherited Summary

From class WorldElement
public

Sets the color in HEX format of the element.

public

Sets the cursor style when the mouse is over the element.

public

Flag for enabling or diabling this element.

public

Flag set when the element is being dragged around.

public

Sets the font of the element.

public

Sets the current height of the element.

public

Flag for allowing the element to be dragged around.

public

Sets the move style of the element.

public

Flag set when the mouse is over the element.

public

Sets a callback function for when the element is dragged around.

public

Sets the position of the element.

public

Sets the renderer used for the element.

public

Sets the rotation of the element.

public

A copy of the z-index value is stored here.

public

Sets the drawing scale of the element.

public

Flag for determining if the element will be a top-most element when dragged around.

public

Flag used to determine if an object is a child of WorldElement.

public

Sets the current width of the element.

public

Sets the world where this element is found.

public

Sets the z-index of the element.

public

Adds the provided coordinates to the position.

public

Sets if the element is draggable.

public

Function called when the mouse moves to check if the pointer is over the element.

public

Sets the color in HEX format of the element.

public

Sets the position of the element.

public

Sets the scale of the element.

public

setZ(z: number)

Sets the z-index of the element.

private

resize()

Function called when the canvas gets resized.

private

setWorld(world: World)

Sets the world object where element will be drawn.

private

topmost(state: boolean)

Sets the element as a topmost element.

Public Constructors

public constructor(path: string, opts: object) source

Override:

WorldElement#constructor

Params:

NameTypeAttributeDescription
path string

Path for the image.

opts object
  • optional

Object that contains valid Picture properties with values. Their values will be assigned at the end of the constructor. If an invalid property is passed then the value will be ignored.

Public Members

public height: number source

Height of the scaled image in units.

Override:

WorldElement#height

public img: object source

Image object where picture will be loaded.

public isDraggable: boolean source

Flag for allowing the picture to be dragged around. Default value is true.

Override:

WorldElement#isDraggable

public loaded: boolean source

Flag for when the image has fully loaded. It is set after the onload event fires.

public pivot: object source

Sets the pivot point around which the picture is drawn. Must be a number between 0 and 1.

Properties:

NameTypeAttributeDescription
x number

X pivot point for the image.

y number

Y pivot point for the image.

public width: number source

Width of the scaled image in units.

Override:

WorldElement#width

Public Methods

public isLoaded(): boolean source

Tests if the image is fully loaded. This means that its properties such as the width are available.

Return:

boolean

True if the image is fully loaded, false otherwise.

Private Methods

private draw() source

Main draw function for the picture called by the World automatically.

private isMouseOver(): boolean source

Tests if the mouse is over the picture.

Override:

WorldElement#isMouseOver

Return:

boolean

True if the mouse is over the picture, false otherwise.