Constructor
new Obstacle(x, y, vx, w, h)
Constructs a new obstacle.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x position of the obstacle |
y |
number | The y position of the obstacle |
vx |
number | The horizontal velocity of the obstacle |
w |
number | The width of the obstacle |
h |
number | The height of the obstacle |
- Source:
Methods
draw()
Draws the obstacle at the correct location on the canvas. If the
obstacle image was not loaded correctly a rectangle will be drawn in its
place.
- Source:
reset()
Resets the obstacle
- Source:
setPos(x)
Sets the horizontal position of the obstacle.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The new horizontal position |
- Source:
setSprite(img)
Sets the sprite image for the obstacle.
Parameters:
Name | Type | Description |
---|---|---|
img |
p5.Image | The new sprite image |
- Source:
setVel(vx)
Sets the horizontal velocity of the obstacle.
Parameters:
Name | Type | Description |
---|---|---|
vx |
number | The new horizontal velocity |
- Source:
update()
Updates the object during the physics loop by moving it to the side. If
The object goes off the canvas it will be wrapped around to the other
side.
- Source: