-
Notifications
You must be signed in to change notification settings - Fork 1
Installation‐and‐Setup
Joshua Tollette edited this page Oct 28, 2025
·
2 revisions
Get Emotive Engine running in 5 minutes.
npm install @joshtol/emotive-engine<script src="https://unpkg.com/@joshtol/emotive-engine@2.5.1/dist/emotive-engine.min.js"></script><!DOCTYPE html>
<html>
<head>
<title>My Emotive App</title>
<style>
#mascot-canvas {
width: 400px;
height: 400px;
border: 1px solid #ccc;
}
</style>
</head>
<body>
<canvas id="mascot-canvas"></canvas>
<script type="module" src="app.js"></script>
</body>
</html>import EmotiveMascot from '@joshtol/emotive-engine';
// Get canvas element
const canvas = document.getElementById('mascot-canvas');
// Create mascot instance
const mascot = new EmotiveMascot({
canvasId: 'mascot-canvas',
targetFPS: 60,
defaultEmotion: 'neutral'
});
// CRITICAL: Initialize with canvas element
await mascot.init(canvas);
mascot.start();
// Try it out!
mascot.setEmotion('joy');
mascot.morphTo('heart');
mascot.express('bounce');Problem: Cannot read property 'getContext' of null
Solution: Ensure canvas element exists before calling init()
// ❌ Wrong - canvas might not exist yet
const mascot = new EmotiveMascot({canvasId: 'canvas'});
await mascot.init(canvas);
// ✅ Correct - wait for DOM to load
document.addEventListener('DOMContentLoaded', async () => {
const canvas = document.getElementById('canvas');
const mascot = new EmotiveMascot({canvasId: 'canvas'});
await mascot.init(canvas);
mascot.start();
});Problem: Nothing renders or errors occur
Solution: Always call init(canvas) before start() and always await init
// ❌ Wrong
mascot.start();
await mascot.init(canvas);
// ❌ Wrong - forgot to await
mascot.init(canvas);
mascot.start();
// ✅ Correct
await mascot.init(canvas);
mascot.start();Problem: Canvas appears blurry or pixelated
Solution: Set canvas size in CSS, not HTML attributes
<!-- ❌ Wrong -->
<canvas id="canvas" width="400" height="400"></canvas>
<!-- ✅ Correct -->
<canvas id="canvas"></canvas>
<style>
#canvas {
width: 400px;
height: 400px;
}
</style>import { useEffect, useRef } from 'react';
import EmotiveMascot from '@joshtol/emotive-engine';
function MascotComponent() {
const canvasRef = useRef(null);
const mascotRef = useRef(null);
useEffect(() => {
const initMascot = async () => {
mascotRef.current = new EmotiveMascot({
canvasId: 'mascot-canvas'
});
await mascotRef.current.init(canvasRef.current);
mascotRef.current.start();
};
initMascot();
return () => {
mascotRef.current?.destroy();
};
}, []);
return <canvas ref={canvasRef} id="mascot-canvas" />;
}See react-component.jsx for complete example.
'use client';
import { useEffect, useRef } from 'react';
import EmotiveMascot from '@joshtol/emotive-engine';
export default function MascotComponent() {
const canvasRef = useRef(null);
const mascotRef = useRef(null);
useEffect(() => {
const initMascot = async () => {
mascotRef.current = new EmotiveMascot({
canvasId: 'mascot-canvas'
});
await mascotRef.current.init(canvasRef.current);
mascotRef.current.start();
};
initMascot();
return () => mascotRef.current?.destroy();
}, []);
return <canvas ref={canvasRef} id="mascot-canvas" />;
}<template>
<canvas ref="canvas" id="mascot-canvas"></canvas>
</template>
<script>
import EmotiveMascot from '@joshtol/emotive-engine';
export default {
mounted() {
this.initMascot();
},
beforeUnmount() {
this.mascot?.destroy();
},
methods: {
async initMascot() {
this.mascot = new EmotiveMascot({
canvasId: 'mascot-canvas'
});
await this.mascot.init(this.$refs.canvas);
this.mascot.start();
}
}
}
</script>For better performance on mobile devices:
const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
const mascot = new EmotiveMascot({
canvasId: 'mascot-canvas',
particleCount: isMobile ? 150 : 300,
adaptiveQuality: true,
targetFPS: isMobile ? 30 : 60
});- API Reference - Learn all methods
- Examples Gallery - See working code
- Troubleshooting - Common issues and fixes
- Live Demo - Interactive playground