Skip to content
CalSch edited this page Apr 27, 2021 · 9 revisions

Docs for HeliumJS v0.1


Game(canvas, frameRate)

Initializes a Game object.
Parameters:

  • canvas: (Canvas) The canvas for the game to draw on
  • frameRate: (Number) The rate of the game loop (Optional, default is 60)

Properties:

  • canvas: (Canvas) The canvas to draw on
  • screenWidth: (Number)The canvas' width
  • screenHeight: (Number) The canvas' height
  • frame: (Number) The current frame, increments every game loop
  • bgColor: (String) The background color of the game screen (Default: #ffffff)
  • running: (Bool) If the game is running
  • deltaTime: (Number) The number of milliseconds since the last frame
  • sprites: (List) The sprites in the game, (Use addSprite to add a sprite instead of manually adding one)
  • pressedKeys: (Dict) The keys being pressed (Ex. If D is pressed game.pressedKeys.d returns true)
  • activeCamera: (Camera) The active camera, (Use setCamera to set the active camera)
  • mousePos: (Object) The current position of the mouse (Ex. To get the mouse X position use game.mousePos.x)

Canvas(width,height,id)

Initializes a Canvas object.
Parameters:

  • width: (Number) Width of the canvas
  • height: (Number) Height of the canvas
  • id: (String) id of the canvas element

Properties:

  • width: (Number) Width of the canvas
  • height: (Number) Height of the canvas
  • id: (String) id of the canvas element
  • element: (HTML Element) The HTML element of the canvas
  • ctx: (Context2d) The 2d context of the canvas

Rectangle(x,y,w,h,color)

Initializes a Rectangle object.
Parameters:

  • x: (Number) Center X position
  • y: (Number) Center Y position
  • w: (Number) Width of the rectangle
  • h: (Number) Height of the rectangle
  • color: (String) Color of the rectangle

Properties:

  • x: (Number) Center X position
  • y: (Number) Center Y position
  • w: (Number) Width of the rectangle
  • h: (Number) Height of the rectangle
  • color: (String) Color of the rectangle
  • scripts: (List) The list of scripts it has (Each script gets run on update)

Circle(x,y,r,color)

Initializes a Circle object.
Parameters:

  • x: (Number) Center X position
  • y: (Number) Center Y position
  • r: (Number) Radius of the circle
  • color: (String) Color of the circle

Properties:

  • x: (Number) Center X position
  • y: (Number) Center Y position
  • r: (Number) Radius of the circle
  • color: (String) Color of the circle
  • scripts: (List) The list of scripts it has (Each script gets run on update)

Image(x,y,w,h,src)

Initializes a Image object.
Parameters:

  • x: (Number) Center X position
  • y: (Number) Center Y position
  • w: (Number) Width of the image
  • h: (Number) Height of the image
  • src: (String) Link to the image

Properties:

  • x: (Number) Center X position
  • y: (Number) Center Y position
  • w: (Number) Width of the image
  • h: (Number) Height of the image
  • src: (String) Link to the image
  • elm: (HTML Element) Element of the image (not added to the document)
  • scripts: (List) The list of scripts it has (Each script gets run on update)

Text(x,y,text,style)

Initializes a Text object.
Parameters:

  • x: (Number) Top-left X position
  • y: (Number) Top-left Y position
  • text: (String) The text to display
  • style: (String) The style of the text (eg. 12px red)

Properties:

  • x: (Number) Top-left X position
  • y: (Number) Top-left Y position
  • text: (String) The text to display
  • style: (String) The style of the text (eg. 12px red)
  • scripts: (List) The list of scripts it has (Each script gets run on update)

Sprite(update,draw) (Incomplete)

A base plate for making custom sprites.
Parameters:

  • update: (Function) Update function (Gets called every frame update)
  • draw: (Function) Draw function (Gets called after every frame update)

Properties:

  • update: (Function) Update function (Gets called every frame update)
  • draw: (Function) Draw function (Gets called after every frame update)
  • scripts: (List) The list of scripts it has

Camera(x,y)

A camera for the game
Parameters:

  • x: (Number) Top-left X position
  • y: (Number) Top-left Y position

Properties:

  • x: (Number) Top-left X position
  • y: (Number) Top-left Y position
  • scripts: (List) The list of scripts it has (Unused)