Class: GameTextInput

GameTextInput(center, attrs)

Text Input class

Constructor

new GameTextInput(center, attrs)

Constructor for Text Input element

Parameters:
Name Type Description
center Point

Center point of the element

attrs Object

Attribute object

Properties:
Name Type Description
width number

Width of the text input element

height number

Height of the text input element

color string

Background color of the element (default 'aliceblue')

text string

Text displayed/entered on the element

message string

Text displayed on the popup. Default 'Enter text'

onEnter Array.<function()>

Array of [callback,attribute_object] called on enter text (on popup)

Source:

Extends

Members

x

Overrides:
Source:

y

Overrides:
Source:

Methods

addChild(child, sort)

Adds drawable to the children array

Parameters:
Name Type Default Description
child GameDrawable

Added drawable

sort boolean true

Sorts children array on true. False speeds addition but requires sorting later for correct display

Overrides:
Source:

addHitbox(radius, dx, dy)

Creates and adds a new hitbox

Parameters:
Name Type Default Description
radius number

Radius of hitbox

dx number 0

Deviation on X axis

dy number 0

Deviation on Y axis

Overrides:
Source:

addOnClickListener(callback)

Adds a listener to the array of listeners for onClick

Parameters:
Name Type Description
callback function

function to be called

Overrides:
Source:

addOnDragListener(callback)

Adds a listener to the array of listeners for onDrag

Parameters:
Name Type Description
callback function

function to be called

Overrides:
Source:

addOnEnterTextListener(callback)

Adds a listener to the array of listeners for onEnter

Parameters:
Name Type Description
callback function

function to be called

Source:

addOnFinishDraggingListener(callback)

Adds a listener to the array of listeners for onFinishDragging

Parameters:
Name Type Description
callback function

function to be called

Overrides:
Source:

addOnFinishMouseHoldListener(callback)

Adds a listener to the array of listeners for onFinishMouseHold

Parameters:
Name Type Description
callback function

function to be called

Overrides:
Source:

addOnKeyHoldListener(key, callback, stagger)

Adds a listener to the array of listeners for onKeyHold

Parameters:
Name Type Default Description
key string

Key the callback will be called for

callback function

function to be called

stagger number 0

Skips this many calls

Overrides:
Source:

addOnKeyPressListener(key, callback)

Adds a listener to the array of listeners for onKeyPress

Parameters:
Name Type Description
key string

Key the callback will be called for

callback function

function to be called

Overrides:
Source:

addOnKeyUpListener(callback)

Adds a listener to the array of listeners for onKeyUp

Parameters:
Name Type Description
callback function

function to be called

Overrides:
Source:

addOnMouseHoldListener(callback, stagger)

Adds a listener to the array of listeners for mouse hold

Parameters:
Name Type Default Description
callback function

function to be called

stagger number 0

how many calls are skipped (higher = slower execution)

Overrides:
Source:

addOnMoveListener(callback)

Adds a listener to the array of listeners for move

Parameters:
Name Type Description
callback function

function to be called

Overrides:
Source:

addOnStartDraggingListener(callback)

Adds a listener to the array of listeners for onStartDragging

Parameters:
Name Type Description
callback function

function to be called

Overrides:
Source:

animate()

Updates the animation on every child of type GameGif

Overrides:
Source:

animateTo(point, steps)

Animates movement of the element to the point

Parameters:
Name Type Default Description
point Point

Point to animate to

steps number 10

How many steps in animation. Lower = faster

Overrides:
Source:

click(event)

Calls the functions in the onClick array

Parameters:
Name Type Description
event Object

Event passed from listener

Overrides:
Source:

collidesWith(other) → {boolean}

Returns true on collision with the other element

Parameters:
Name Type Description
other GameElement

Element with which the collision is checked

Overrides:
Source:
Returns:

True on colision else false

Type
boolean

copy(newName) → {GameTextInput}

Returns copy of current instance.

Parameters:
Name Type Description
newName string

Name of the newly created instance. Names have to be unique.

Overrides:
Source:
Returns:

New instance with the same attributes.

Type
GameTextInput

createGif(gifName, attrs) → {GameGif}

Creates, adds and returns a new instance of GameGif

Parameters:
Name Type Description
gifName string

Name of gif without extension

attrs Object

Attributes

Overrides:
Source:
Returns:

Newly created instance

Type
GameGif

createImage(imageName, attrs) → {GameImage}

Creates, adds and returns a new instance of GameImage

Parameters:
Name Type Description
imageName string

Name of image WITH extension

attrs Object

Attributes

Overrides:
Source:
Returns:

Newly created instance

Type
GameImage

createShape(type, attrs) → {GameShape}

Creates, adds and returns a new instance of GameShape

Parameters:
Name Type Description
type TYPE

Type of shape (rectangle,oval,line,polygon)

attrs Object

Attributes, line and polygon require coords attribute

Overrides:
Source:
Returns:

Newly created instance

Type
GameShape

createText(text, attrs) → {GameText}

Creates, adds and returns a new instance of GameText

Parameters:
Name Type Description
text string

Text to be displayed

attrs Object

Attributes

Overrides:
Source:
Returns:

Newly created instance

Type
GameText

drag(mousePos, delta, event)

Calls the functions in the onDrag array

Parameters:
Name Type Description
mousePos Point

Mouse position

delta Point

Deviation of the mouse position (when clicked) from the center

event Event
Overrides:
Source:

draw(ctx)

Transforms the canvas context and calls draw function of every visible child

Parameters:
Name Type Description
ctx CanvasRenderingContext2D

Rendering context of the canvas

Overrides:
Source:

finishDragging()

Calls the functions in the onFinishDragging array

Overrides:
Source:

finishMouseHold(event)

Stops and resets mouse hold interval

Parameters:
Name Type Description
event
Overrides:
Source:

getAttrs() → {Object}

Returns object of attributes of current instance.

Overrides:
Source:
Returns:

Attribute object.

Type
Object

getChildByName(name) → {GameDrawable|GameGif|GameShape|GameText|GameImage}

Returns child drawable with input name or throws an error

Parameters:
Name Type Description
name string

Searched name

Overrides:
Source:
Returns:

Found child drawable

Type
GameDrawable | GameGif | GameShape | GameText | GameImage

home()

Returns element to home position

Overrides:
Source:

isInside(mouse) → {boolean}

Checks if mouse is inside any of the instance's child

Parameters:
Name Type Description
mouse Point

Mouse position

Overrides:
Source:
Returns:

True when inside

Type
boolean

keyHold(key)

Calls the functions in the onKeyHold object that are assigned to the passed keys

Parameters:
Name Type Description
key string

Array of currently pressed keys

Overrides:
Source:

keyPress(key, event)

Calls the functions in the onKeyPress object that are assigned to the passed keys

Parameters:
Name Type Description
key string

Array of currently pressed keys

event Event
Overrides:
Source:

keyUp(event)

Calls the functions in the onKeyUp array and resets stagger values for onKeyHold

Parameters:
Name Type Description
event
Overrides:
Source:

move(delta, triggerOnMove)

Moves the element by vector delta and calls onMove callbacks

Parameters:
Name Type Default Description
delta Point

Vector by which the element is moved

triggerOnMove boolean true

Calls the onMove callbacks on true

Overrides:
Source:

popChildByName(name) → {GameDrawable}

Removes element from elements array and returns it, or throws an error

Parameters:
Name Type Description
name string

Name of element to be removed

Overrides:
Source:
Returns:

Removed element

Type
GameDrawable

removeOnClickListener(callback)

Removes listener for the onClick event

Parameters:
Name Type Description
callback function

function you want to remove

Overrides:
Source:

removeOnDragListener(callback)

Removes listener for the onDrag event

Parameters:
Name Type Description
callback function

function you want to remove

Overrides:
Source:

removeOnEnterTextListener(callback)

Removes listener for the onEnterText event

Parameters:
Name Type Description
callback function

function you want to remove

Source:

removeOnFinishDraggingListener(callback)

Removes listener for the onFinishDragging event

Parameters:
Name Type Description
callback function

function you want to remove

Overrides:
Source:

removeOnFinishMouseHoldListener(callback)

Removes listener for the onFinishDragging event

Parameters:
Name Type Description
callback function

function you want to remove

Overrides:
Source:

removeOnKeyHoldListener(key, callback)

Removes listener for the onKeyHold event

Parameters:
Name Type Description
key string

Key from which the listener is removed from

callback function

function you want to remove

Overrides:
Source:

removeOnKeyPressListener(key, callback)

Removes listener for the onKeyPress event

Parameters:
Name Type Description
key string

Key from which the listener is removed from

callback function

function you want to remove

Overrides:
Source:

removeOnKeyUpListener(callback)

Removes listener for the onKeyUp event

Parameters:
Name Type Description
callback function

function you want to remove

Overrides:
Source:

removeOnMouseHoldListener(callback)

Removes listener for mouse hold

Parameters:
Name Type Description
callback function

function you want to remove

Overrides:
Source:

removeOnMoveListener(callback)

Removes listener for the onClick event

Parameters:
Name Type Description
callback function

function you want to remove

Overrides:
Source:

removeOnStartDraggingListener(callback)

Removes listener for the onStartDragging event

Parameters:
Name Type Description
callback function

function you want to remove

Overrides:
Source:

setHome(x, y)

Sets home position

Parameters:
Name Type Description
x number
y number
Overrides:
Source:

setPosition(x, y)

Changes the position of element to values

Parameters:
Name Type Description
x number

X coordinate

y number

Y coordinate

Overrides:
Source:

sortChildren()

Sorts children array by level

Overrides:
Source:

startDragging()

Calls the functions in the onStartDragging array

Overrides:
Source:

startMouseHold(event)

Creates mouse hold interval

Parameters:
Name Type Description
event
Overrides:
Source: