From 74be46ad523c40ebf52d919ff39d60b79db059aa Mon Sep 17 00:00:00 2001 From: Rob Walker Date: Sat, 4 Nov 2023 17:42:45 +0000 Subject: [PATCH] Step 2 --- App.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/App.js b/App.js index ceec8d0..369539b 100644 --- a/App.js +++ b/App.js @@ -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 (