Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Lightweight library for HTML5 2D Game Development

branch: master
README.md

Pentagine

About

Pentagine is a lightweight Javascript library for HTML5 2D Game Development that renders to <canvas>. For now, it consists of a State Machine, a Sprite class to load and draw images and some keyboard input functions. Soon, I expect it to have much more.

Example

Clone pentagine with git clone git@github.com:davidgomes/pentagine.git and then open examples/index.html for a list of examples.

Here's a small example of all the Javascript code necessary to draw a ball and make it movable:

function PlayState() {
  this.setup = function() {
    this.ball = new Sprite("ball.png", 100, 50);
  }

  this.update = function() {
    if (isDown("up"))
      this.ball.y--;
    else if (isDown("down"))
      this.ball.y++;
    else if (isDown("left"))
      this.ball.x--;
    else if (isDown("right"))
      this.ball.x++;
  }

  this.draw = function() {
    clearCanvas();

    this.ball.draw();
  }
}

/*
   If desiredFPS is not declared, the game will run as fast as
   possible, and on any State, you can use 'this.dt' to get the
   delta time between two ticks and use it to make movement
   smooth. If desiredFPS is declared, this.dt also works.
*/
desiredFPS = 60;

/* Prevents the following keys to be sent to the web page. */
preventKeys("down", "right", "left", "right", "space");

switchState(new PlayState());

A "real-life" example of a game that uses Pentagine is Multitaskor, a game I created for Ludum Dare 27.

License

Pentagine is licensed under the MIT License.

Thanks

I'd like to thank to ippa because Pentagine is inspired on his HTML5 Game Development library - jaws. I also used some of his code, but this is not a fork, the two libraries are quite different.

Pentagine also uses stats.js, a great monitor for HTML5 performance. It was made by mrdoob, who is credited on the LICENSE.

Something went wrong with that request. Please try again.