new Ball(p_context, p_init)
This:
Parameters:
| Name | Type | Description |
|---|---|---|
p_context |
CanvasRenderingContext2D | The 2d context of the canvas upon which the ball is to be drawn. |
p_init |
Object | An object that contains initialization values for the attributes
rInit, xInit, yInit,
vxInit, vyInit,
borderWidth, borderColor,
and color. |
- Source:
Properties:
| Name | Type | Description |
|---|---|---|
r |
Number | The radius of the ball. |
x |
Number | The x-position of the ball. |
y |
Number | The y-position of the ball. |
vx |
Number | The vx-velocity of the ball. |
vy |
Number | The vy-velocity of the ball. |
rInit |
Number | Array | The initial radius of the ball. |
xInit |
Number | Array | The initial x-position of the ball. |
yInit |
Number | Array | The initial y-position of the ball. |
vxInit |
Number | Array | The initial vx-velocity of the ball. |
vyInit |
Number | Array | The initial vy-velocity of the ball. |
borderWidth |
int | The width of the border of the ball. |
borderColor |
String | The color of the border of the ball. |
color |
String | The color of the ball. |
Methods
-
draw()
-
Draws the ball at its current position onto a 2d context.
-
move(p_delta_t)
-
Moves the ball in direction (vx,vy); the step size depends on FPS.
Parameters:
Name Type Description p_delta_tNumber The time elapsed since the last call of move. -
reset()
-
Resets the ball: Moves the ball to its starting position and computes randomly a velocity vector.