0

enter image description hereTrying to develop a game using react-three-fiber with a timer. Im trying to create the timer based on a react function. The problem is, after wrapping the timer to the scene (the gameplay), it overlays the game and only the timer appears.

return (
<Provider store={store}>
  <Router>
    <Fragment>
      <Route exact path="/" component={Landing} />
      <section className="container">
        <Alert />
        <Switch>
          <Route exact path="/register" component={Register} />
          <Route exact path="/login" component={Login} />
          <PrivateRoute exact path="/dashboard" component={Dashboard} />
          <PrivateRoute exact path="/instruction" component={Instruction} />
          <PrivateRoute exact path="/dashboard2" component={Dashboard2} />
          <PrivateRoute exact path="/profile" component={Profile} />
          <PrivateRoute exact path="/intro" component={Intro} />
          <Timer />
          <PrivateRoute exact path="/scene1" component={Scene1} />
          <PrivateRoute exact path="/scene2" component={Scene2} />
        </Switch>
      </section>
    </Fragment>
  </Router>
</Provider>
);
  • `Switch` will render first matching `Route` or `Redirect`. Does `Timer` return either of those? If the current path isn't matched by any route above `Timer` then only `Timer` will render, the switch stops trying to match. – Drew Reese Aug 05 '20 at 08:44
  • the path above Timer doesnt have any problem. What I want to achieve is that the Timer will wrapped and still continue to countdown around those two Scenes (Scene1 and Scene2). But after trying it, the timer only appears on the scene. – clydekarnage Aug 05 '20 at 08:50
  • you have two options, first, you can move Timer component inside both of Scene1 and Scene2, or you can move Timer outside the switch, and use conditional rendering which depends on the url path if it's /scene1 or /scene2, but I don't recommend this, the first approach is better – Ali Abu Hijleh Aug 05 '20 at 08:56
  • yeah already tried the first one but the problem is that the timer will not continue when going to the 2nd scene. – clydekarnage Aug 05 '20 at 09:02
  • its just that the canvas/scene of the game disappeared after adding the timer. – clydekarnage Aug 05 '20 at 09:06

0 Answers0