fix: for render
This commit is contained in:
parent
22d6bbb3c4
commit
60f32d8659
|
@ -17,28 +17,36 @@ const View = ({json}) => {
|
|||
const {Entity} = latus.get('%resources');
|
||||
const [entity, setEntity] = useState(new Entity());
|
||||
useEffect(() => {
|
||||
setEntity(new Entity());
|
||||
const container = ref.current;
|
||||
let handle;
|
||||
let renderer;
|
||||
const loadEntity = async () => {
|
||||
const entity = await Entity.load(json);
|
||||
if (!entity.is('Visible')) {
|
||||
return undefined;
|
||||
return;
|
||||
}
|
||||
entity.setPosition(Vector.scale(Rectangle.size(entity.visibleAabb), 4));
|
||||
const renderer = new Renderer(Vector.scale(Rectangle.size(entity.visibleAabb), 8));
|
||||
entity.tick(0);
|
||||
const size = Vector.max(Rectangle.size(entity.visibleAabb), [64, 64]);
|
||||
entity.setPosition(Vector.scale(size, 4));
|
||||
renderer = new Renderer(Vector.scale(size, 8));
|
||||
ref.current.appendChild(renderer.element);
|
||||
const handle = setInterval(() => {
|
||||
handle = setInterval(() => {
|
||||
entity.tick(0.03);
|
||||
entity.renderTick();
|
||||
renderer.render(entity.container);
|
||||
}, 33.33);
|
||||
setEntity(entity);
|
||||
return () => {
|
||||
ref.current.removeChild(renderer.element);
|
||||
if (handle) {
|
||||
clearInterval(handle);
|
||||
}
|
||||
};
|
||||
};
|
||||
loadEntity();
|
||||
return () => {
|
||||
if (renderer) {
|
||||
container.removeChild(renderer.element);
|
||||
}
|
||||
if (handle) {
|
||||
clearInterval(handle);
|
||||
}
|
||||
};
|
||||
}, [Entity, json, ref]);
|
||||
return (
|
||||
<div className="entity-view">
|
||||
|
|
Loading…
Reference in New Issue
Block a user