This demo is a sandbox application to play with Shaku. Write code below to update the Shaku app on the right.
// call runGame() to start your game
async function runGame()
{
// init shaku
await Shaku.init();
// add shaku's canvas to document and set resolution to 800x600
document.body.appendChild(Shaku.gfx.canvas);
// load a texture asset and a font texture
let texture = await Shaku.assets.loadTexture('assets/shaku.png');
let fontTexture = await Shaku.assets.loadFontTexture('assets/DejaVuSansMono.ttf', {fontName: 'DejaVuSansMono'});
// create a sprite batch
let spritesBatch = new Shaku.gfx.SpriteBatch();
// create a text sprite batch
let textSpriteBatch = new Shaku.gfx.TextSpriteBatch();
// do a single main loop step
function step()
{
// start new frame and clear screen
Shaku.startFrame();
Shaku.gfx.clear(Shaku.utils.Color.cornflowerblue);
// draw test texture
spritesBatch.begin();
let position = Shaku.gfx.getCanvasSize().div(2);
let size = new Shaku.utils.Vector2(256, 256);
let rotation = Shaku.gameTime.elapsed;
spritesBatch.drawQuad(texture, position, size, null, null, rotation);
spritesBatch.end();
// draw welcome text
textSpriteBatch.begin();
let textGroup = Shaku.gfx.buildText(fontTexture, "Shaku is ready for battle!", 24, Shaku.utils.Color.white, Shaku.gfx.TextAlignments.Center);
textGroup.position.set(position.x, position.y + 160);
textSpriteBatch.drawText(textGroup);
textSpriteBatch.end();
// PUT YOUR GAME LOGIC HERE
// make fullscreen
Shaku.gfx.maximizeCanvasSize(false);
// end frame and request next frame
Shaku.endFrame();
Shaku.requestAnimationFrame(step);
}
// start main loop
step();
}
// initiate the game
runGame();