因此,我正在尝试访问引擎内的调度功能,但是抛出一个错误,指出引擎为空。我认为这样做的原因是因为每个组件都是同时加载的,所以它不等待引擎设置为ref。
有任何处理技巧吗?也许会延迟组件的创建?
render() {
return (
<View style={styles.container}>
<GameEngine
ref={(ref) => { this.engine = ref }}
style={styles.container}
systems={[GameLoop]}
entities={{
Character: {position: [230, 400], velocity:[1,0],renderer: <Character />}
}}
>
<StatusBar hidden />
{/* <Playerinfo /> */}
<Joystick style={styles.joystick} position={[230, 650]} onPress={this.engine.dispatch({ type: 'test'})} />
</GameEngine>
</View>
);
}