-
Notifications
You must be signed in to change notification settings - Fork 0
/
StartFlagComponent.tsx
63 lines (58 loc) · 1.56 KB
/
StartFlagComponent.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import React, {useMemo} from 'react';
import {
useImage,
ImageShader,
Shader,
Vertices,
Rect,
SharedValueType,
} from '@shopify/react-native-skia';
import {useDerivedValue} from 'react-native-reanimated';
import {GameState} from './GameState';
import {shader} from './Shader';
import {indicies, get_verticies} from './utils';
export const START_SIDE = 64;
export const START_FRAMES = 16;
const start_vertices = get_verticies(START_SIDE);
export type StartFlagProps = {
game_state: SharedValueType<GameState>;
pd: number;
};
export function StartFlagComponent(props: StartFlagProps) {
const pd = props.pd;
const shader_scale = useMemo(() => [{scale: pd}], [pd]);
const start = useImage(require('./images/start_64x64.png'));
const transform = useDerivedValue(() => {
let {x, y} = props.game_state.value.start;
return [{translateY: y * pd}, {translateX: x * pd}] as [
{translateY: number},
{translateX: number},
];
});
const uniforms = useDerivedValue(() => {
const {x_offset} = props.game_state.value.start;
return {x_offset, y_offset: 0};
});
if (!start) {
return null;
}
return (
<>
<Rect
transform={transform}
x={0}
y={0}
width={START_SIDE * pd}
height={START_SIDE * pd}>
<Shader transform={shader_scale} source={shader!} uniforms={uniforms}>
<ImageShader image={start} />
</Shader>
<Vertices
textures={start_vertices}
vertices={start_vertices}
indices={indicies}
/>
</Rect>
</>
);
}