opt: render and compositing
This commit is contained in:
parent
49c050fe91
commit
8b5b62829e
|
@ -3,7 +3,9 @@ import {usePropertyChange} from '@avocado/react';
|
||||||
import {RoomUi} from '@avocado/topdown';
|
import {RoomUi} from '@avocado/topdown';
|
||||||
import {
|
import {
|
||||||
React,
|
React,
|
||||||
|
useEffect,
|
||||||
useFlecks,
|
useFlecks,
|
||||||
|
useRef,
|
||||||
} from '@flecks/react';
|
} from '@flecks/react';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -15,13 +17,34 @@ import styles from './index.module.scss';
|
||||||
|
|
||||||
const PlayUi = () => {
|
const PlayUi = () => {
|
||||||
const {config: {'@humus/app': {resolution}}} = useFlecks();
|
const {config: {'@humus/app': {resolution}}} = useFlecks();
|
||||||
|
const ref = useRef();
|
||||||
const room = useRoom();
|
const room = useRoom();
|
||||||
const selfEntity = useSelfEntity();
|
const selfEntity = useSelfEntity();
|
||||||
|
const viewSize = usePropertyChange(selfEntity?.camera, 'viewSize', [0, 0]);
|
||||||
|
const {camera} = selfEntity || {};
|
||||||
|
// Update the transform.
|
||||||
|
useEffect(() => {
|
||||||
|
if (!ref.current || !room || !camera) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const onRealOffsetChanged = () => {
|
||||||
|
const translated = Vector.mul(
|
||||||
|
Vector.scale(camera.realOffset, -1),
|
||||||
|
Vector.div(resolution, viewSize),
|
||||||
|
);
|
||||||
|
ref.current
|
||||||
|
.style.transform = `translate(${translated[0]}px, ${translated[1]}px)`;
|
||||||
|
};
|
||||||
|
camera.on('realOffsetChanged', onRealOffsetChanged);
|
||||||
|
return () => {
|
||||||
|
camera.off('realOffsetChanged', onRealOffsetChanged);
|
||||||
|
};
|
||||||
|
}, [camera, ref, resolution, room, viewSize]);
|
||||||
return (
|
return (
|
||||||
<div className={styles.ui}>
|
<div className={styles.ui}>
|
||||||
<RoomUi
|
<RoomUi
|
||||||
domScale={Vector.div(resolution, usePropertyChange(selfEntity?.camera, 'viewSize', [0, 0]))}
|
domScale={Vector.div(resolution, viewSize)}
|
||||||
position={Vector.scale(usePropertyChange(selfEntity?.camera, 'realOffset', [0, 0]), -1)}
|
ref={ref}
|
||||||
room={room}
|
room={room}
|
||||||
/>
|
/>
|
||||||
{selfEntity && <Hotbar selfEntity={selfEntity} />}
|
{selfEntity && <Hotbar selfEntity={selfEntity} />}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
.ui {
|
.ui {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
position: relative;
|
// Move children to a separate composite layer.
|
||||||
|
position: absolute;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user