如何解决ImageStore已从React-native
我正在尝试使用expo-phaser
来构建带有react-native的2D游戏。我需要在RN中完成此游戏,然后将其集成到现有的应用中。在安装unimodules
以便能够在裸反应本机项目上使用expo模块之后,现在出现此错误:
主要组件的代码是:
const Assets = {
'map.json': require('assets/map.json'),'dirt.png': require('assets/dirt.png'),};
export default class App extends React.Component {
state = {loading: false};
async componentwillMount() {
const downloads = [];
for (let key of Object.keys(Assets)) {
const asset = Asset.fromModule(Assets[key]);
downloads.push(asset.downloadAsync());
}
await Promise.all(downloads);
this.setState({loading: false});
}
render() {
if (this.state.loading) {
return (
<View>
<Text>loading</Text>
</View>
);
}
return (
<GLView
style={{flex: 1}}
onContextCreate={(context) => startGame({context})}
/>
);
}
}
function startGame({context}) {
const game = ExpoPhaser.game({context});
game.state.add('Playable',{
preload: function () {
const tileMap = Asset.fromModule(Assets['map.json']).localUri;
const dirt = Asset.fromModule(Assets['dirt.png']).localUri;
game.load.tilemap(
'tilemap',tileMap,null,ExpoPhaser.Phaser.Tilemap.TILED_JSON,);
game.load.image('dirt',dirt);
},create: function () {
game.stage.backgroundColor = '#4488AA';
game.physics.startSystem(ExpoPhaser.Phaser.Physics.ARCADE);
},update: function () {},});
game.state.start('Playable');
}
谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。