• Content Count

  • Joined

  • Last visited

Posts posted by Lukripar

  1. I have a class Player.js that handles the creation of my player, and I have game.js which is where I run my game. What is the correct way in the game.js to call the Player class?


    for example:

    let player;

    class Game extends Phaser.Scene{



    player = this.add.sprite(400,400,'dude');

    this.player = new Player(this);


    my assets are handled in a preload scene. The italics portion is what I'm having problems with. It keeps saying Player is not defined.

    if I try to import it into the game.js file, I get an unexpected token error.


    Thank you for your help.


  2. I'm trying to code a simple game using scenes. I am new to Phaser 3 and relatively new to coding in general so I may be making a dumb mistake. I've just hit a wall.

    I'm trying to get my main menu "start" button to start the game state. Simple enough right? But when I run the files on http-server, i get:

    ``ncaught ReferenceError: Game is not defined
        at testmain.js:6``


    my html:

    <!doctype html>
    <html lang="en">
    <meta charset="UTF-8" />
    <title>FCM Classes Test</title>
    <script src="//"></script>
    <canvas id="canvas"></canvas>
    <script type="module" src="js/testmain.js"></script>
    <script type="module" src="js/scenes/game.js"></script>
    <script src="js/scenes/mainMenu.js"></script>
    <script src="js/scenes/preload.js"></script>


    var config = {
    type: Phaser.AUTO,
    width: 800,
    height: 800,
    parent: "#canvas",
    scene: [Preload, MainMenu, Game ],
    title: 'Fantasy Cage Match'
    let game = new Phaser.Game(config);



    let startButton, menubg;
    class MainMenu extends Phaser.Scene{
    constructor() {
    super({key: "MainMenu"});
    this.menubg = this.add.image(400,400,'menubg');
    this.startButton = this.add.sprite(400, 400, 'startbutton').setInteractive();
    this.startButton.on('pointerdown', function startGame(pointer){
    }, this);

    and my game.js I haven't added any other code because I just want to see my sprite move around on screen.. (I know i haven't done anything with cursors yet..)

    import Player from '../characters/Player.js'
    let bg, cursors, player;
    class Game extends Phaser.Scene{
    constructor() {
    super({key: "gamescene"});
    bg = this.add.image(400,400,'background');
    player = this.add.sprite(400,400,'dude');
    this.player = new Player(this)

    First time posting, so I'm sorry if I didn't follow correct etiquette. Thanks in advance for any ideas.