Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

109
Visualizações
How to display the Phaser Game Screen only in a Route React?

I want that my game screen only been displayed in '/game' route, but when I give the boot with method "new Phaser.Game(config)" he start shows in every route '/home', default rote '/', '/error', '/game' and etc.

game.js

import Phaser from 'phaser';
import LoadScene from './scenes/LoadScene.js';
import MenuScene from './scenes/MenuScene.js';

export const config = {
  type: Phaser.AUTO,
  width: 800,
  height: 600,
  scene: [ MenuScene, LoadScene]
};

const game = new Phaser.Game(config);

gamepage.js

import config from '../../phaser/game.js';
import React from 'react';

export default class GamePage extends React.Component {
    render() {
        return <>
            <Game />
        </>;
    }
}

routes.js

import React from 'react';
import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
import ErrorPage from '../pages/error/index.js';
import Home from '../pages/home/index.js';
import GamePage from '../pages/game/index.js';

export default class Rotas extends React.Component {
    render() {
        return <>
            <Router>
                <Routes>
                    <Route path="/" element={<Home />} />
                    <Route path="/game" elememnt={<GamePage />} />
                    <Route path="*" element={<ErrorPage />} />
                </Routes>
            </Router>
        </>
    };
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The config object in new Phaser.Game(config); accepts a parent option, which specifies the element that will contain the game canvas. If it is undefined then it will be included in the document body (your case).

You can specify null so that it is not included anywhere, and you are responsible for adding it to the DOM.

See https://newdocs.phaser.io/docs/3.55.2/Phaser.Types.Core.GameConfig#GameConfig for the available options.

You can also have a look at How to integrate Phaser into React as they use that approach

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda