Button
Parameters | Type | Description | Default Value |
---|---|---|---|
string | string |
Image URL or color code format. | "color:#FFFFFF" |
[x, y] | number[] |
The top left position of the button in pixels. | [0, 0] |
[width, height] | number[] |
The width and height of the button in pixels. | [64, 16] |
text | string |
The text of the button, if undefined it will be disabled. | "Button" |
fontFamily | string |
The fontFamily for the button text. | "sans-serif" |
textColor | string |
The color of the text | "#FFFFFF" |
textMargin | number |
The margin of the text | 0 |
timeoutMS | number |
The time it takes for the button to be able to be pressed again . | 0 |
Attributes
Attributes | Description |
---|---|
image |
Holds the image object if an image source is provided. |
usingColor |
Indicates whether the button is using a color instead of an image. |
color |
Holds the color value if the button is using a color. |
x, y |
Current position of the button. |
width, height |
Dimensions of the button. |
halfwidth, halfheight |
Half of the width and height of the button. |
pos |
Position coordinates of the button in an array x: [0], y: [1]. |
text |
Object for handling text functionality. |
text.active |
A boolean flag indicating whether the text should be active/shown or not. |
text.color |
Color of the text. |
text.text |
The current text of the button. |
text.size |
The size in px of the text. |
text.margin |
Margin for the text |
text.fontFamily |
The fontFamily |
text.baseline |
Baseline for text "top" , "middle" , "bottom" , or "alphabetic" . |
text.align |
Text alignment: "start" , "end" , "left" , "right" , or "center" . |
text.stroke.active |
A boolean flag indicating whether the stroke (outline) should be active or not. |
text.stroke.color |
A string representing the color of the stroke in hexadecimal, RGB, or other supported formats. |
text.stroke.width |
A numerical value representing the width of the stroke in pixels. |
click |
Boolean that indicates if its being clicked. |
hover |
Boolean that indicates if its being hovered. |
hitbox |
Hitbox object for collision detection. |
anglex, angley |
Position coordinates used for positioning calculations. Has nothing in common with angle ! |
angle |
Angle of rotation for the button (in degrees). |
alpha |
Transparency of the button. |
radius |
The amount of rounding corners use array for changing independently each corner or a number to change all corners. |
stroke.active |
A boolean flag indicating whether the stroke (outline) should be active or not. |
stroke.color |
A string representing the color of the stroke in hexadecimal, RGB, or other supported formats. |
stroke.width |
A numerical value representing the width of the stroke in pixels. |
left, right, top, bottom |
Boundaries of the button. |
timeout |
The timeout object. When clicked it will activate and while active the click var will stay false. |
Methods
draw()
The draw() method is responsible for rendering the button onto the canvas based on its current properties.
Example
setText()
The setText() method changes the text and fits it to the button with a provided font and text
Failure
setText() uses fitext that doens't properly fit text with some fonts.
Parameters | Type | Description | Default Value |
---|---|---|---|
text | string |
The text to be changed | - |
fontFamily | string |
The fontFamily that is goind to be changed | - |
Example
changeImage(string)
Changes the image/color of the button.
Parameters | Type | Description | Default Value |
---|---|---|---|
string | string |
Image URL or color code format. | - |
grow(x, y)
Increases or decreases the size of the button.
Parameters | Type | Description | Default Value |
---|---|---|---|
x | number |
Amount by which to increase width | - |
y | number |
Amount by which to increase height | - |