|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
import React, {useEffect, useRef, useState} from "react";
|
|
|
|
|
import React, {useEffect, useRef} from "react";
|
|
|
|
|
import "../../style/player.css";
|
|
|
|
|
import Draggable, {ControlPosition, DraggableBounds} from "react-draggable";
|
|
|
|
|
import Draggable, {DraggableBounds} from "react-draggable";
|
|
|
|
|
|
|
|
|
|
export default function Player({id, x, y, bounds}: {
|
|
|
|
|
id: number,
|
|
|
|
@ -9,11 +9,11 @@ export default function Player({id, x, y, bounds}: {
|
|
|
|
|
bounds: DraggableBounds
|
|
|
|
|
}) {
|
|
|
|
|
|
|
|
|
|
const ref = useRef<HTMLDivElement>();
|
|
|
|
|
const ref = useRef<HTMLDivElement>(null);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const playerRect = ref.current?.getBoundingClientRect();
|
|
|
|
|
bounds.bottom -= playerRect.height / 2;
|
|
|
|
|
bounds.right -= playerRect.width / 2;
|
|
|
|
|
const playerRect = ref.current!.getBoundingClientRect();
|
|
|
|
|
bounds.bottom! -= playerRect.height / 2;
|
|
|
|
|
bounds.right! -= playerRect.width / 2;
|
|
|
|
|
}, [ref])
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|