April 2020
Intermediate to advanced
716 pages
18h 55m
English
In order to render the VR game based on the game the user chose to play from the MERN VR Game application, we need to retrieve the corresponding game ID from the link that loads the VR game view. In the index.js file of the React 360 project folder, we will update the componentDidMount method to first retrieve the game ID from the incoming URL, and then make a fetch call to the load game API, as shown in the following code:
/MERNVR/index.js:
componentDidMount = () => { let gameId = Location.search.split('?id=')[1] read({ gameId: gameId }).then((data) => { if (data.error) { this.setState({error: data.error}); } else { this.setState({ vrObjects: data.answerObjects.concat(data.wrongObjects), game: data }); Environment.setBackgroundImage( ...Read now
Unlock full access