✅ Solved: Trying to run the famous girl-with-mouse-tracker animation that Marvin Te created
Hi everyone,
I am trying to run this animation: https://rive.app/marketplace/19397-36522-girl-animation-cursor-tracking/
Girl Animation (Cursor Tracking)
The thing is.. the animation works, but just for a second. I am doing something wrong and I don’t know what it is.
GitHub link: https://github.com/itay-perry/rive-lottie-talk/tree/main/04-rive-community
This is my code:
<body>
<div id="container">
<canvas id="canvas" width="800" height="800"></canvas>
</div>
<script src="https://unpkg.com/@rive-app/webgl2"></script>
<script>
let moveX;
let moveY;
const canvas = document.getElementById("canvas");
const r = new rive.Rive({
src: "./girl_animation_(cursor_tracking).riv",
canvas: document.getElementById("canvas"),
autoBind: true,
autoplay: true,
onLoad: () => {
r.resizeDrawingSurfaceToCanvas();
// Access the current instance that was auto-bound
const namedVM = r.viewModelByName("View Model 1");
const vmiDefault = namedVM.defaultInstance();
r.bindViewModelInstance(vmiDefault);
moveY = vmiDefault.number("Mouse Y");
moveX = vmiDefault.number("Mouse X");
console.log(moveY, moveX);
},
});
// DOM loaded
document.addEventListener("DOMContentLoaded", () => {
debugger;
// listener for mouse coordianted x, y
canvas.addEventListener("mousemove", (e) => {
const x = e.clientX;
const y = e.clientY;
console.log(y, x);
moveY.value = y;
moveX.value = x;
// console.log(x, y);
});
});
</script>Does anyone see a problem here? The animation is loaded and even seems to track to mouse movement for a second before it gets stuck.
I would love for some help please, if you can 🙏🏽