Jump to content

How can i simulate a multilevel map in a phaser 3 scene?


ValerioC
 Share

Recommended Posts

I'm creating a 2d game with a top-down based camera and i was trying to make a map with more than 1 level. I'm getting a lot of problems when the player has to pass from one level to another.

At the moment the transition from one level to the other would take place through two rectangles positioned at the beginning and at the end of the stairs (which are the only points where the player can change levels).

when the player overlaps these two rectangles the setDepth is modified and I would like that when the player rises to the second level then the first level becomes the subject of collision while when it goes down to the first level it deactivates a collision with the first level and activates with the second. This is what I came up with the idea of doing to create a sort of layer manager

that's the code i did for this:

    this.map=this.make.tilemap({
      key: "map",
      tileWidth: 2048,
      tileHeight: 1792,
    });

    this.layer_2=this.map.createLayer("level_2",this.tileset,0,0);
    this.layer_3=this.map.createLayer("level_3",this.tileset,0,0);

creating map and layers

    this.zone = this.add.zone(256, 455,64,32);
    this.physics.world.enable(this.zone);

    this.zone2 = this.add.zone(256, 391,64,32);
    this.physics.world.enable(this.zone2);

    this.layer_2.setCollisionBetween(1,999);
    this.layer_3.setCollisionBetween(1,999);

creating the 2 zone and adding collisions

    this.physics.add.overlap(this.player,this.zone,()=>{
      this.physics.world.removeCollider(this.collider1);
      this.player.setDepth(4);
      this.physics.world.colliders.add(this.collider2);
      console.log("zone1");
    });

    this.physics.add.overlap(this.player,this.zone2,()=>{
      this.physics.world.removeCollider(this.collider2);
      this.player.setDepth(6);
      this.physics.world.colliders.add(this.collider1);
      console.log("zone2");
    });

adding the overlap events that switch the collision level

All this works really bad because when the player overlap the rectangle i need to wait like 200 iterations or more of the overlap function for the collision with the next layer to be eliminated and the collision with the previous layer added

I would also appreciate any advice on how to improve the logic of all this.

I hope i was clear, and thanks to every one will watch this and maybe answare me. Thank you so much

 

immagine.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...