-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🛸🛹 ↝ [ SGV2-10 GP-15 GP-14 ] animations and other stuff
- Loading branch information
1 parent
250f64d
commit 2c0fdec
Showing
4 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import Image from 'next/image'; | ||
|
||
const PlanetCharacter: React.FC = () => { | ||
const [angle, setAngle] = useState<number>(0); | ||
// State to store animation direction (1 for right, -1 for left) | ||
const [direction, setDirection] = useState<number>(1); | ||
|
||
// Function to update animation angle and direction | ||
const updateAnimation = () => { | ||
// Increment angle based on direction | ||
const newAngle = angle + 1 * direction; | ||
// Change direction when angle reaches certain limits | ||
if (newAngle >= 10 || newAngle <= -10) { | ||
setDirection(direction * -1); | ||
} | ||
// Update angle | ||
setAngle(newAngle); | ||
}; | ||
|
||
// Update animation angle every 50 milliseconds | ||
useEffect(() => { | ||
const interval = setInterval(updateAnimation, 50); | ||
return () => clearInterval(interval); // Cleanup interval on unmount | ||
}, [angle, direction]); | ||
|
||
return ( | ||
<div className="relative w-64 h-64"> | ||
<Image | ||
src="/assets/Inventory/Planets/Mars caricature.png" // Replace with the path to your character image | ||
alt="Character" | ||
width={256} | ||
height={256} | ||
className="transform transition-transform duration-500" | ||
style={{ transform: `rotate(${angle}deg)` }} // Apply rotation based on angle | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PlanetCharacter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.