Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@ const Game = () => {
],
}));

// Setup the device motion sensor listener
React.useEffect(() => {
// Set the update interval to 16ms (60fps)
DeviceMotion.setUpdateInterval(16);

const subscription = DeviceMotion.addListener((deviceMotionMeasurment) => {
// Update the ball position based on the device motion sensor.
ballAnimation.value = {
// Change the value of the ball's x position by the device motion sensor's gamma value
x: getConstrainedBallX(
ballAnimation.value.x + deviceMotionMeasurment.rotation.gamma * 12
),
// Change the value of the ball's y position by the device motion sensor's beta value
y: getConstrainedBallY(
ballAnimation.value.y + deviceMotionMeasurment.rotation.beta * 12
),
};
});

return subscription.remove;
}, []);

return (
<View style={styles.container}>
<Reanimated.View style={[styles.ball, ballPosition]} />
Expand Down