Skip to content

Commit 88c758a

Browse files
committed
"update src/components/animation"
1 parent 92bcdd9 commit 88c758a

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

src/components/animation.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Matter from 'matter-js';
55

66

77
// Create an engine
8-
const { Engine, Render, Runner, World, Bodies } = Matter;
8+
const { Engine, Render, Runner, World, Bodies,Mouse, MouseConstraint } = Matter;
99

1010
declare global {
1111
interface Window {
@@ -80,7 +80,31 @@ export default function MatterSimulation(){
8080
{ x: 0, y: window.innerHeight },
8181
]);
8282
};
83+
// Add a stack of boxes
84+
for (let i = 0; i < 5; i++) {
85+
const box = Bodies.rectangle(300 + i * 60, 100, 50, 50, {
86+
render: {
87+
fillStyle: '#00ff00',
88+
},
89+
});
90+
World.add(world, box);
91+
}
92+
93+
94+
95+
const mouse = Mouse.create(render.canvas);
96+
const mouseConstraint = MouseConstraint.create(engine, {
97+
mouse,
98+
constraint: {
99+
stiffness: 0.2,
100+
render: {
101+
visible: false,
102+
},
103+
},
104+
});
83105

106+
World.add(world, mouseConstraint);
107+
render.mouse = mouse;
84108
window.addEventListener('resize', handleResize);
85109

86110
// Cleanup

0 commit comments

Comments
 (0)