A lightweight HTML5 Canvas JavaScript library
//variables
var obj;
// startGame is called once
function startGame() {
obj = new component(30, 30, "red", 0, 0);
// start the engine
myGameArea.start();
}
// updateGameArea is called once per frame
function updateGameArea() {
// clear canvas every frame
myGameArea.clear();
obj.newPos();
obj.update();
}
<!DOCTYPE html>
<html lang="en">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<title>Hyrdaboo2D demo</title>
</head>
<style>
html {
user-select: none;
}
canvas {
background: #303030;
position: fixed;
width:100%;
height:100%;
top:0;
left:0;
}
</style>
<body>
<!-- use this link to access the library internally -->
<script src="https://raw.githack.com/Hyrdaboo/Hyrdaboo2D/main/Hyrdaboo2D.min.js"></script>
<script src="main.js"></script>
</body>
</html>
myGameArea.start()
– Starts the enginemyGameArea.clear()
- Clears canvas per framemyGameArea.stop()
- clears Intervalcomponent(width, height, "color", x, y, type)
- create a new game object-
- type = "textureMaterial" - add texture on an object (write image src instead of color parameter)
- type = "circle" - create circle shaped game object
obj.color = color value
- change color of an objectobj.strokeColor = color value
- change border color of a circle
obj.touchTrace = bool
- touchtrace enabled/disabled (for touch devices )obj.followMouse = bool
- move with cursor enabled/disabledsetVibration(int)
- vibrateviewFullscreen(orientation)
- enter full-screen modeobj.clicked()
- detect if object is clicked
camera.x = int
- camera xcamera.y = int
- camera yscale = int
- zoom in/out (in development)
obj.speedX = int
- set x velocityobj.speedY = int
- set y velocityobj.acceleration = int
- set accelerationobj.addForce = int
- add force to an objectobj.gravity = int
- set gravityobj.gravitySpeed = int
- set gravity acceleration indexobj.Mu = int
- set roughness of a surfaceobj.bounce = int
- set bounciness of an objectobj.mass = int
- set Massobj.angle = int
- angleobj.rotatable = bool
- set rotatable
obj.boxColliding(otherobj)
- box collisionobj.crashWith(otherobj)
- box collision2obj.circleColliding(otherobj)
- circle collisionobj.boxCircleColliding(otherobj)
- circle with box collisionobj.hitCanvasEdge()
- hit canvas(viewport) borders