Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Layer world position


Harold
 Share

Recommended Posts

I am trying to load multiple maps into different positions within the world. I figured out that the world bounds can be negative (I think/hope), so I can seamlessly load maps in all directions. However, when I try to set a layer's X and Y it seems to be fixed to the camera and keeps the X and Y at 0. So I do fixedToCamera = false, but then it seems to mess up the camera scrolling (camera scrolls around world bounds, but layers move randomly).

It also seems like this should be much easier to do. Shouldn't I be able to just move the entire map to say -1000, -1000, another map to -1000, 0, another to -1000, 1000 instead of having to move each map's layers?

I am using game.world.setBounds to go into negative X and Y by the way. Any help? Thank you in advance.

Link to comment
Share on other sites

Something just doesn't seem right about this. I am either doing some wrong setting or it's just not able to work.

So I'm setting the game bounds to -1024, -1024, 3096 width, 3096 height which allows me to fit 9 1024x1024 maps in a 3x3 grid. After that I set the camera bounds to the game bounds I set. Then I load the 9 maps all in their proper positions (-1024, -1024; -1024, 0; -1024, 1024; etc).

In order to load those maps in those positions I have tried different things, none of which work. When I create the map layers, I have tried layer.position.setTo, layer.x/layer.y, and layer.worldPosition. They all did the same thing pretty much. I have tried all of those with fixedToCamera as true and false. When it's set to true, it will just load all the maps at 0,0 it seems and when it's false it will mess the camera up and load the maps in weird positions.

I would really like some help with this. Is there a setting I am missing in the game to allow this?

Link to comment
Share on other sites

From the docs on Phaser.TilemapLayer:

Quote

By default TilemapLayers have fixedToCamera set to true. Changing this will break Camera follow and scrolling behavior.

So that's what you're seeing. Technically, I don't think this can really work with the current implementation of Tilemaps in Phaser, at least not like that.

What about accessing the tilemap straight from the cache and then parsing it yourself by calling putTile on the appropriate layers?

Link to comment
Share on other sites

5 hours ago, drhayes said:

From the docs on Phaser.TilemapLayer:

So that's what you're seeing. Technically, I don't think this can really work with the current implementation of Tilemaps in Phaser, at least not like that.

What about accessing the tilemap straight from the cache and then parsing it yourself by calling putTile on the appropriate layers?

I was really hoping that I could just get it to work without rigging it up. It seems like it should work fine, I feel like there's something I'm missing.

4 hours ago, VitaZheltyakov said:

Do not use setting boundaries of the world.

Only camera.bounds

I have to set the boundaries of the world so I can move freely. I tested it that way and it still didn't work anyways.

Anyway, here's a screenshot of the problem. I have debug = true and it's showing collision boxes as you can see. I am at -40, 63, it's letting me move around and it's also drawing layers in negative space (albeit in the wrong position of course). It seems so simple like it should be working but there's a problem. Game holds the world, world holds the map, map holds the layers. I need to move the entire map around the world to the appropriate spots, so it seems like the map should be able to just move all of its children to wherever I need them to within the world. I need to do it this way so I can handle online better so everyone can have their appropriate X and Y within the world.

phaserbug.png

Link to comment
Share on other sites

55 minutes ago, Harold said:

I have to set the boundaries of the world so I can move freely. I tested it that way and it still didn't work anyways.

You should not make negative boundaries of in the world. It breaks down the mechanism for calculating coordinates.

Link to comment
Share on other sites

29 minutes ago, VitaZheltyakov said:

You should not make negative boundaries of in the world. It breaks down the mechanism for calculating coordinates.

I was hoping it would allow me to scale the world northwest seamlessly. I need to be able to scroll in all directions so I can create new maps.

Link to comment
Share on other sites

Well it works now. The problem was the camera was applying it's scrolling to every layer at the same time. So in order to get it fixed you need to:

layer.fixedToCamera = false;
layer.scrollFactorX = 0;
layer.scrollFactorY = 0;
layer.position.setTo(x, y);

This will allow you to place the layer(s) wherever you want within the world without the camera's scroll offset affecting it. You can then world.setBounds(x, y, width, height) to whatever you'd like. In my game so far it is set -1024, -1024, 3072, 3072 and as the player moves I will be expanding it depending on where they are moving to.

However the one problem with this is the collision doesn't seem to be working, but I haven't tested the collision much at all after I just got this to work.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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