Constructor
new GameComposite(elements, attrs)
GameComposite constructor
Parameters:
Name | Type | Description |
---|---|---|
elements |
Array.<GameElement> | |
attrs |
Object |
Properties:
Name | Type | Description |
---|---|---|
elements |
Array.<{element: GameElement, clickable: boolean, draggable: boolean, pressable: boolean}> | Elements instances + their original settings |
- Source:
Extends
Members
x
- Overrides:
- Source:
y
- Overrides:
- Source:
Methods
(protected) _addPosition()
- Source:
(protected) _subtractPosition()
- Source:
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:
addElement(element)
Adds element to composite, silences some of its functions
Parameters:
Name | Type | Description |
---|---|---|
element |
GameElement |
- Source:
addElements(…elements)
Adds multiple elements to composite, some of its functions are turned off
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
elements |
GameElement |
<repeatable> |
- 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:
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:
addToGame(game)
Adds all elements to game
Parameters:
Name | Type | Description |
---|---|---|
game |
Game |
- Source:
animate()
Animates elements
- 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) → {GameComposite}
Creates a new copy of composite with all its elements. They aren't added to game. Use game.copyElement() instead
Parameters:
Name | Type | Description |
---|---|---|
newName |
string |
- Overrides:
- Source:
Returns:
New instance
- Type
- GameComposite
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()
Draws elements
- 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 attribute object with copies of elements
- 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
hasElements() → {boolean}
Returns true when it has elements
- Source:
Returns:
value
- Type
- boolean
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
removeElement(element)
Removes element from composite, returns its functions
Parameters:
Name | Type | Description |
---|---|---|
element |
GameElement |
- Source:
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:
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:
reset()
Removes all subElements from composite and returns their functions
- Source:
rotateElements(origin, angle, keepOrientation)
Rotates elements around a point
Parameters:
Name | Type | Default | Description |
---|---|---|---|
origin |
Point | Point around which elements are rotated |
|
angle |
number | Angle in radians |
|
keepOrientation |
boolean | false | Elements don't change their rotation value on true |
- Source:
setCenter(x, y)
Sets center of composite without moving child elements
Parameters:
Name | Type | Description |
---|---|---|
x |
number | |
y |
number |
- Source:
setHome(x, y)
Sets home position
Parameters:
Name | Type | Description |
---|---|---|
x |
number | |
y |
number |
- Overrides:
- Source:
setPosition(x, y)
Sets position of composite.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | |
y |
number |
- Overrides:
- Source:
sortChildren()
Sorts children array by level
- Overrides:
- Source:
sortElements()
Sorts elements by level
- Source:
startDragging()
Calls the functions in the onStartDragging array
- Overrides:
- Source:
startMouseHold(event)
Creates mouse hold interval
Parameters:
Name | Type | Description |
---|---|---|
event |
- Overrides:
- Source: