// components import Lottie from 'lottie-react'; import Spring from '@components/Spring'; // assets // import ball from '@assets/logo.json'; import logo from '@assets/dropcoin.json'; import flycoin from '@assets/flycoin.json'; import {useEffect, useRef, useState} from "react"; import styled from "styled-components/macro"; import SoundHelp from "@utils/SoundManger"; const objInfo={ timerIds:[] } const DropCoins = ({...props}) => { const [isShow, setIsShow] = useState(false); const coinRef = useRef(null); const coins = [useRef(null),useRef(null),useRef(null),useRef(null)] const show=()=>{ setIsShow(true); } const hide=()=>{ setIsShow(false); } const resetTimer=()=>{ if (objInfo.timerIds){ for (let i = 0; i < objInfo.timerIds; i++) { clearTimeout(objInfo.timerIds[i]); } objInfo.timerIds=[]; } } useEffect(()=>{ const dropCoins={ show, hide }; global.dropCoins=dropCoins; },[]) useEffect(() => { resetTimer(); if (isShow){ let timer=setTimeout(()=>{ coinRef.current.setSpeed(1.5); coinRef.current.play(); SoundHelp.playSound("sound_bonus"); },100) objInfo.timerIds.push(timer); coins.forEach((coin,i)=>{ let timer_1=setTimeout(()=>{ coin.current.play(); // coin.current.setSpeed(1.4+i*0.2); },i*500) objInfo.timerIds.push(timer_1); let timer_2=setTimeout(()=>{ coin.current.play(); coin.current.setSpeed(0.9-(3-i)*0.1); },i*500+100) objInfo.timerIds.push(timer_2); }) let timer_3=setTimeout(()=>{ setIsShow(false); },8000); objInfo.timerIds.push(timer_3); } }, [isShow]); return ( <> { isShow?( {/**/} ):(<>) } ) } export default DropCoins;