My game

I want to create a browser strategy game in Phaser, how do I create a game map ?

I want the map to be created from repeated sprites, how do i create a sprite ?

i asked chatGPT and it gave me an answer, i created this 2 files index.html

Phaser Game

Jocul tău Phaser

<!-- Include fișierul GameScene.js -->
<script src="scenes/GameScene.js"></script>

<!-- Script pentru inițializarea și pornirea jocului -->
<script>
  var config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    scene: [GameScene],
  };

  var game = new Phaser.Game(config);
</script>

and GameScene.js

// scenes/GameScene.js

class GameScene extends Phaser.Scene {
constructor() {
super({ key: “GameScene” });
}

preload() {
// Încarcă resursele necesare, cum ar fi tilemap-urile, imagini etc.
this.load.tilemapTiledJSON(“map”, “assets/maps/level1.json”);
this.load.image(“tiles”, “assets/tilesets/tmw_desert_spacing.tsx”);
}

create() {
// Creează harta de joc și alte elemente
var map = this.make.tilemap({ key: “map” });
var tileset = map.addTilesetImage(“tmw_desert_spacing”, “tiles”);
var groundLayer = map.createLayer(“Ground”, tileset);
var camera = this.cameras.main;
camera.setBounds(0, 0, map.widthInPixels, map.heightInPixels);
}

update() {
// Logica de actualizare a jocului
}
}

// Asigură-te că clasa este disponibilă global
window.GameScene = GameScene;

problem is when i run index.html it gives me the error : GameScene is not defined

could you tell me what happens to your code when you remove the window.GameScene = GameScene please?

just a second

same error, GameScene is not defined

okay put that line of code back there.

maybe try putting your config and your game code in the same script. make sure to put config AFTER the game code.

ok let me try

Error is gone, I put the script from index.html at the end of GameScene.js

awesome, so it works now?

but why it doesnt work in separate files ?

I think this is because the GameScene was not carried over between the imports

so one script knew what GameScene was but the other that your localhost was connected to did not

hence you got the error GameScene is undefined

thx a lot for the help !!! :slight_smile: i will use this topic to ask more questions as i get into trouble

no problem, also you should create new topics if you have new questions :chair:

ok then ill do so, thx again :slight_smile: