DropCoins.jsx 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // components
  2. import Lottie from 'lottie-react';
  3. import Spring from '@components/Spring';
  4. // assets
  5. // import ball from '@assets/logo.json';
  6. import logo from '@assets/dropcoin.json';
  7. import flycoin from '@assets/flycoin.json';
  8. import {useEffect, useRef, useState} from "react";
  9. import styled from "styled-components/macro";
  10. import SoundHelp from "@utils/SoundManger";
  11. const objInfo={
  12. timerIds:[]
  13. }
  14. const DropCoins = ({...props}) => {
  15. const [isShow, setIsShow] = useState(false);
  16. const coinRef = useRef(null);
  17. const coins = [useRef(null),useRef(null),useRef(null),useRef(null)]
  18. const show=()=>{
  19. setIsShow(true);
  20. }
  21. const hide=()=>{
  22. setIsShow(false);
  23. }
  24. const resetTimer=()=>{
  25. if (objInfo.timerIds){
  26. for (let i = 0; i < objInfo.timerIds; i++) {
  27. clearTimeout(objInfo.timerIds[i]);
  28. }
  29. objInfo.timerIds=[];
  30. }
  31. }
  32. useEffect(()=>{
  33. const dropCoins={
  34. show,
  35. hide
  36. };
  37. global.dropCoins=dropCoins;
  38. },[])
  39. useEffect(() => {
  40. resetTimer();
  41. if (isShow){
  42. let timer=setTimeout(()=>{
  43. coinRef.current.setSpeed(1.5);
  44. coinRef.current.play();
  45. SoundHelp.playSound("sound_bonus");
  46. },100)
  47. objInfo.timerIds.push(timer);
  48. coins.forEach((coin,i)=>{
  49. let timer_1=setTimeout(()=>{
  50. coin.current.play();
  51. // coin.current.setSpeed(1.4+i*0.2);
  52. },i*500)
  53. objInfo.timerIds.push(timer_1);
  54. let timer_2=setTimeout(()=>{
  55. coin.current.play();
  56. coin.current.setSpeed(0.9-(3-i)*0.1);
  57. },i*500+100)
  58. objInfo.timerIds.push(timer_2);
  59. })
  60. let timer_3=setTimeout(()=>{
  61. setIsShow(false);
  62. },8000);
  63. objInfo.timerIds.push(timer_3);
  64. }
  65. }, [isShow]);
  66. return (
  67. <>
  68. {
  69. isShow?(
  70. <Spring {...props} className="d-flex align-items-center justify-content-center flex-1 w-100 h-100 top_view">
  71. <Lottie lottieRef={coinRef} loop={false} autoplay={false} className="top_view" animationData={logo} speed={1.5} />
  72. {/*<Lottie loop={false} animationData={flycoin} className="top_view" style={{marginLeft:"-15rem"}} />*/}
  73. <Lottie loop={false} lottieRef={coins[0]} autoplay={false} animationData={flycoin} className="top_view" style={{marginLeft:"-70%",marginTop:"-25rem",width:"25rem"}} />
  74. <Lottie loop={false} lottieRef={coins[1]} autoplay={false} animationData={flycoin} className="top_view" style={{marginLeft:"-20%",marginTop:"-35rem",width:"18rem"}} />
  75. <Lottie loop={false} lottieRef={coins[2]} autoplay={false} animationData={flycoin} className="top_view" style={{marginRight:"-20%",marginTop:"-15rem",width:"20rem"}} />
  76. <Lottie loop={false} lottieRef={coins[3]} autoplay={false} animationData={flycoin} className="top_view" style={{marginRight:"-60%",marginTop:"-20rem",width:"22rem"}}/>
  77. </Spring>
  78. ):(<></>)
  79. }
  80. </>
  81. )
  82. }
  83. export default DropCoins;