JavaScript API

If you make a game from scratch or modify an existing one that isn't built for Minicade, you'll probably want to use the Tinygame library, which makes it easy for Minicade to talk to your game.

To use it, add the following script tag to your HTML:

<script src="//minicade.herokuapp.com/tinygame.js"></script>

When you do this, you'll notice a gray bar at the top of your page. This is simulating the Minicade time bar, which shows the player how long they have to complete your game. Tinygame also simulates various events that Minicade will send your game throughout its lifecycle.

When Minicade shows your game to the player, Tinygame.onplay is called, so you'll want to start your game logic at that time, like so:

Tinygame.onplay = function() {
  // Start accepting user input, animating sprites, etc...
  console.log("Game started!");
};

When the player runs out of time, Tinygame.onoutoftime is called, so you'll want to register a callback for that, too:

Tinygame.onoutoftime = function() {
  // Stop accepting user input, show ending animation, etc...
  console.log("Player ran out of time!");
};

Alternatively, at some point the player might win your game. When this happens, call Tinygame.win() to inform Minicade of their victory, so the player's score can be updated and Minicade can move on to the next game. Or, if the player prematurely falls off a cliff, you can use Tinygame.lose().

Tinygame supports a few more features; these are just the basics. You can learn more in the Tinygame documentation.

Can I use my favorite HTML5 gaming library?

Absolutely! Minicade uses a micro-framework called Fancy Friday to embed your game in an <iframe> element. Your game can use whatever libraries it wants.

However, there is a need for Minicade to communicate with your game. For example:

  • Minicade needs to tell your game what the current difficulty level is.
  • Minicade needs to tell your game how much time the player has to complete your game.
  • Your game needs to tell Minicade what the player's score is.

To facilitate this communication, your game is expected to implement a bit of plumbing, which Tinygame does for you.

If you don't like Tinygame, you're free to write your own integration code, so long as it conforms to the Embedded Microgame API. Other than that, you're welcome to use whatever libraries you like to create your game!