Class: Floor

PlayScene.Floor(scene, x, y)

- This will create the floor and will move and update the top part to give the illusion of movement in space. This class is used to easily manage and manipulate the floor. It will animate the tilesprite's X position in the update method.

Constructor

new Floor(scene, x, y)

Sets up the default values for the class variables.
Parameters:
Name Type Description
scene this is the current Scene object.
x the starting x pos of the floor. Used in case the floor needs to be repositioned, or positioned starting elsewhere from the left of the screen.
y the starting y pos of the floor. Used in case the floor needs to be repositioned, or positioned starting elsewhere from the bottom of the screen.
Author:
  • Christian P. Auman
Source:

Methods

create()

This method will create the ground and the floor to be displayed on the canvas
Source:

getHeight() → {number}

This method returns the total height between the floor and the ground
Source:
Returns:
- the total height between the floor and the ground
Type
number

preload()

This function is called before anything is drawn on the canvas. This allows for asset preloading which prevents anything from drawing without it first loading the asset.
Source:

resetG()

Called whenever the game resets. Sets the game state to IDLE
Source:

startG()

Called whenever the game starts. Sets the game state to RUNNING
Source:

stopG()

Called whenever the game ends. Sets the game state to PAUSED
Source:

update()

If the game state is IDLE or RUNNING, it will call velocityToTilePosition. Basically, It calls it separately in IDLE and RUNNING in case future implementations required different logic or velocities for each state.
Source:

updatePosition()

This method will update the ground and floor using given class position variable
Source:

velocityToTilePosition() → {number}

Based on the given velocity, this returns a new x position that will animate the tileposition.x at the same speed that the physics animatets the moving pipes.
Source:
Returns:
- new tile position
Type
number