toupie is currently in very early state and the API is changing quickly and compatibility is constantly broken.
If you plan on using it before 1.0.0 get released, make sure to pin a specific version.
toupie (french for spinning top, pronounce "to pee") is a flexible game library for TypeScript and JavaScript.
It was originally based of a fork of bottlecap.js. If you are interested in a small Vanilla JS library definitely check that too.
Goals of the project include:
Toupie does not want to lock you in a given architecture like most game engine do. Instead it tries to give you a useful selection of tools to build your game the way you like.
The intended use of toupie is small 2D games.
It is well suited to quick prototyping and game jam creations. But it can also be used for more fleshed out projects.
toupie offer the following tools to build a game:
Everything (except the geometric primitives that are used throughout the library) is opt-in and you can use your own implementation if that's what you want.
The reference generated from inline doc is available here.
Some demos are available here.
toupie can be used both for JS and TS games.
If you want to use it from a TypeScript app, you will have to create a npm or yarn based project.
Simply install toupie and import it from you files.
For example you index.ts may look like that:
import { ready, run } from "toupie";
const game = {}
game.update = function(dt) {
}
game.render = function() {
}
ready(() => {
run(game);
});
And your index.html may look like that:
<!DOCTYPE html>
<html class="default">
<head>
<meta charSet="utf-8"/>
<title>toupie demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE">
</head>
<body>
<script type=module src="./index.ts"/>
</body>
</html>
Then use your favorite build system to build the app into a regular HTML+JS bundle. We recommend parcel.js for its ease of use.
A more complete example of using toupie with TS is provided here.
When writing the code directly in JS you have two options:
The heavy/modern approach is to follow the same steps as for TypeScript but writing you code in JavaScript.
The old school one is to use the compiled version of toupie to build your project.
You can find it in here.
You can simply import this from you index.html:
<!DOCTYPE html>
<html class="default">
<head>
<meta charset="utf-8" />
<title>toupie demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE" />
</head>
<body>
</body>
<script type="module">
import { ready, run } from "https://lattay.srht.pages/toupie/dist/toupie.mjs";
const game = {}
/*
* This method is called by the game engine to update the game on each frame.
* dt is the amount of time elapsed since last frame in seconds.
*/
game.update = function(dt) {
}
/*
* This function is used by the game engine to render the game on each frame.
*/
game.render = function() {
}
ready(() => {
run(game);
});
</script>
</html>
A more complete example of this approach is provided here.
Generated using TypeDoc