Skip to content

Instantly share code, notes, and snippets.

@jhsu
Created April 26, 2017 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhsu/05bcc1cfd8e61c0d143525b1fce4d758 to your computer and use it in GitHub Desktop.
Save jhsu/05bcc1cfd8e61c0d143525b1fce4d758 to your computer and use it in GitHub Desktop.
import React from 'react';
import Camera from './Camera';
import Shake from 'shake.js';
class Player extends Component {
componentDidMount() {
this.shaker = new Shake({
threshold: 5,
timeout: 250,
});
this.shaker.start();
window.addEventListener('shake', this.reorient, false);
}
reorient() {
if (this.camera) {
const rotation = this.camera.getAttribute('rotation');
this.setState({
orientation: { x: 0, y: -1 * rotation.y, z: 0 }
});
}
}
cameraMounted = (camera) => {
this.camera = camera;
}
render() {
return <Camera
rotation={this.state.orientation}
onMount={this.cameraMounted}
/>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment