Skip to content

Commit

Permalink
Sprite.jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
sky-ash committed Nov 1, 2024
1 parent 588d2e1 commit aab61da
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/components/Sprite.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { useState, useEffect } from 'react';
import { Box } from '@mui/material';

export default function Sprite() {
const [spritePosition, setSpritePosition] = useState({ x: 0, y: 0 });

const moveSprite = (x, y) => {
setSpritePosition({ x, y });
};

useEffect(() => {
// Example of moving the sprite to a new position
moveSprite(50, 50);
}, []);

return (
<Box
sx={{
position: 'absolute',
top: `${spritePosition.y}%`,
left: `${spritePosition.x}%`,
width: '30px',
height: '30px',
backgroundColor: 'red',
borderRadius: '50%',
transition: 'top 0.5s, left 0.5s',
}}
/>
);
}

0 comments on commit aab61da

Please sign in to comment.