Documentation


Include TinyPlatforms.js script

<!-- Put this code inside <head> tag of your html file -->
<script src="tinyPlatforms.js"></script>

Initialize TinyPlatforms.js

//Create a new tinyPlatforms object
var tinyPlatforms = new TinyPlatforms();

Create a platform

//Create a new platform
var platform = new Platform(x, y, width, height, isStatic);

//Add the platform to tinyPlatforms
tinyPlatforms.add(platform);

Update platforms

//Update platforms
tinyPlatforms.run();

Render platforms

//Loop through every platform
for (var i = 0; i < tinyPlatforms.platforms.length; i++) {
var p = tinyPlatforms.platforms[i];
//Use rendering engine of choice like p5.js, etc.
rectangle(p.x, p.y, p.width, p.height, "red");
}

Add a player

//Create a new non-static platform that will be the player
var player = new Platform(100, 100, 50, 50, false);

//Add the player to tinyPlatforms
tinyPlatforms.add(player);

//Player move speed
var speed = 5;

//Put in game loop:
if (getKey("a")) {
player.vx = -speed;
} else if (getKey("d")) {
player.vx = speed;
}

//Jump when pressing space
if (getKey("space") && player.isTouchingGround) {
player.vy = -6;
}