Browser game SDK with built-in leaderboards (no backend needed) and mobile-safe audio. Works on iOS Safari. Perfect for AI-generated games.
npm install star-sdkBrowser game SDK with built-in leaderboards (no backend needed), mobile-safe audio, and multiplayer. Works on iOS Safari. Perfect for AI-generated games.
``javascript
import Star from 'star-sdk';
Star.audio.play('coin');
Star.game(ctx => { ... });
Star.leaderboard.submit(1500);
`
| Need | Without Star | With Star |
|------|--------------|-----------|
| Leaderboards | Build a backend, database, auth | Star.leaderboard.submit(score) |Star.audio.play()
| Mobile audio | Handle unlock gestures, AudioContext resume | Just call |
| HiDPI canvas | Manual DPR scaling, coordinate math | Automatic |
| iOS Safari | Debug audio/touch issues for hours | It just works |
`bash`
npx star-sdk init && cat > index.html << 'EOF'
EOF
open index.html # or: python -m http.server
`bash`
npm install star-sdkor
yarn add star-sdk
`javascript
import Star from 'star-sdk';
Star.game(ctx => {
const { canvas, width, height, ctx: c } = ctx;
let score = 0;
// Preload sounds
Star.audio.preload({
coin: 'coin', // Built-in synth preset
jump: 'jump',
});
// Game loop
ctx.loop((dt) => {
c.fillStyle = '#1a1a2e';
c.fillRect(0, 0, width, height);
c.fillStyle = '#fff';
c.font = '24px sans-serif';
c.fillText(\Score: \${score}\, 20, 40);
});
// Input
canvas.onclick = () => {
score += 10;
Star.audio.play('coin');
};
});
`
Procedural sounds and music with built-in presets.
`javascript
// Play built-in sounds
Star.audio.play('coin');
Star.audio.play('laser');
Star.audio.play('explosion');
// Music control
Star.audio.music.crossfadeTo('level2', { duration: 2 });
Star.audio.music.stop(1);
// Volume
Star.audio.setMusicVolume(0.8);
Star.audio.setSfxVolume(0.9);
Star.audio.toggleMute();
`
Built-in presets: \beep\, \coin\, \pickup\, \jump\, \hurt\, \explosion\, \powerup\, \shoot\, \laser\, \error\, \click\, \success\, \bonus\, \select\, \unlock\, \swoosh\, \hit\
Game loop with automatic DPR scaling and coordinate conversion.
`javascript
Star.game(ctx => {
const { canvas, width, height, ctx: c, ui } = ctx;
ctx.loop((dt) => {
// dt = delta time in seconds
c.clearRect(0, 0, width, height);
});
// Delegated events
ctx.on('click', '.button', (e) => { ... });
// UI overlay (HTML on top of canvas)
ui.render(\
);
}, {
preset: 'landscape', // or 'portrait', 'responsive'
});
`$3
Submit scores and display rankings.
`javascript
// Submit score
const result = await Star.leaderboard.submit(1500);
if (result.success) {
console.log(\Ranked #\${result.rank}!\);
}// Show platform UI
Star.leaderboard.show();
// Fetch scores manually
const { scores } = await Star.leaderboard.getScores({
timeframe: 'weekly',
limit: 10
});
`External Games
For games hosted outside the Star platform:
`bash
Register your game
npx star-sdk init "My Game"
`This creates a \
.starrc\ file with your game ID. The SDK auto-detects this configuration.Deploy to Star
Get more from your game with Star hosting:
- Free hosting
- Play session tracking (see how long players play)
- Analytics dashboard
- Discovery / game feed
`bash
npx star-sdk deploy
``- Multiplayer - Real-time game state synchronization (in alpha)
- Monetization - Let players support your games
Full documentation at buildwithstar.com/docs/sdk
MIT