Constructor
new GameRangeSlider()
Properties:
Name | Type | Description |
---|---|---|
width |
number | Width of slider in pixels |
color |
string | Color of the whole slider |
onChange |
Array.<function()> | Events to be trigerred on change of slider value |
scaleElement |
GameShape | Line that represents slider scale |
handleElement |
GameShape | Rectangle that represents slider handle |
bounds |
Object | Maximum value of slider |
- 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:
addOnChangeListener(callback)
Adds a listener to the array of listeners for OnChange
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | function to be called |
- 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:
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) → {GameRangeSlider}
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
- GameRangeSlider
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 an object of attributes (used for copying)
- 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
getPercentValue() → {number}
Returns percent value of the slider based on handle position
- Source:
Returns:
- Type
- number
getValue() → {number}
Returns value of slider
- Source:
Returns:
- Type
- number
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
removeOnChangeListener(callback)
Removes listener for the OnChange event
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | function you want to remove |
- 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:
setBounds(min, max)
Sets minimum and maximum bounds for slider
Parameters:
Name | Type | Default | Description |
---|---|---|---|
min |
number | 0 | |
max |
number | 10 |
- 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:
setValue(value, change)
Sets value of slider and updates position of the handle
Parameters:
Name | Type | Default | Description |
---|---|---|---|
value |
number | Value to be set |
|
change |
boolean | true | False prevents triggering onChange events |
- 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: