Constructor
new Attack()
Creates an instance of Attack.
Loads the attack image, sets its dimensions and position, and adds touch event listeners.
- Source:
Methods
getMouseCoordinates(event) → {Object}
Calculates the mouse or touch coordinates relative to the canvas.
Parameters:
| Name | Type | Description |
|---|---|---|
event |
Event | The mouse or touch event. |
- Source:
Returns:
An object containing the calculated x and y coordinates.
- Type
- Object
handleClick(mouseX, mouseY)
Checks if the provided coordinates are within the bounds of the attack button.
Parameters:
| Name | Type | Description |
|---|---|---|
mouseX |
number | The x coordinate relative to the canvas. |
mouseY |
number | The y coordinate relative to the canvas. |
- Source:
onClick(event)
Handler for the touchstart event.
If the user touches within the button's area, it triggers the attack action.
Parameters:
| Name | Type | Description |
|---|---|---|
event |
TouchEvent | The touch event. |
- Source:
onRelease(event)
Handler for the touchend event.
It ends the attack action by setting the 'D' key in the keyboard object to false.
Parameters:
| Name | Type | Description |
|---|---|---|
event |
TouchEvent | The touch event. |
- Source:
updatePosition()
Updates the position of the attack button based on the canvas size.
- Source: