**The ultra-lightweight game orchestration layer for Canvas API.**
npm install choppy2d-jsjs
choppy.sceneCreate(function(scene, ctx, deltaTime) {
// Layer 1: Background (Bottom)
ctx.fillStyle = 'green';
ctx.fillRect(0,0,200,100);
// Layer 2: Entity (Top)
ctx.fillStyle = 'white';
ctx.fillRect(0,0,50,50);
}, "Cave");
`
2. Performance: Init vs Script
The init function is for setup. The script loop is for logic. Never initialize heavy variables or sprites inside the loop!
Correct ā
(Optimized):
`js
choppy.sceneCreate(
function(scene, ctx, delta) {
// Logic: Move things
window.playerX += 10 * delta;
},
"Level1",
function() {
// Setup: Run once
window.playerX = 0;
}
);
`
Incorrect ā (Memory Leak):
`js
choppy.sceneCreate(function(scene, ctx, delta) {
window.playerX = 0; // ERROR: Resets every frame!
window.sprite = new openfl.display.Sprite(); // ERROR: 60 objects per second!
}, "Level1");
`
š§© Integration with OpenFL (Hybrid Mode)
For frameworks like OpenFL, Choppy acts as the Logic Brain. Remeber that in Openfl or other frameworks with an system of charcaters, delete the global characters in the init of the next scene of that charcaters
`js
var choppy = new Choppy("myCanvas", false, true); // framework_Used = true
choppy.sceneCreate(
function(scene, ctx, delta) {
window.player.x += 10 * delta; // Physics/Logic
},
"GameScene",
function() {
window.player = new openfl.display.Sprite(); // Visual Setup
openfl.Lib.current.stage.addChild(window.player);
}
);
// Call in OpenFL's ENTER_FRAME
openfl.Lib.current.stage.addEventListener("enterFrame", function(e) {
choppy.play(true); // onlyFrameMode = true
});
`
š Quick Start (Speed-run style)
1. Setup your HTML
`html
`
2. Create your Game Logic
`html
``