NoxBrutalis Posted July 19, 2018 Share Posted July 19, 2018 Hi everyone, I'm trying to implement world bounds and can't get it to work. Here's how I'm doing it: this.physics.world.setBounds(0, 0, this.layer1.width, this.layer1.height, true, true, true, true); this.player = new Player(this, objLayer[0].x, objLayer[0].y, 'playerSheet', game).setDepth(3); this.player.body.setCollideWorldBounds(true); this.player.body.onWorldBounds = true; this.physics.world.on('worldbounds', function(body){ console.log('hello from the edge of the world', body); },this); player just walks wherever he damn pleases, like there are no bounds. The only thing I can think is that it's because he's part of a group. I tried adding a collider between the playerGrp and this.physics.world.bounds, but no joy there either. I saw someone in a tutorial setting their player to collide and they didn't use .body, probably because their sprite was extended, and so is mine. So i tried this.player.setCollideWorldBounds(true) also, but that doesn't change anything. All the tutorials I've seen basically do the above and apparently it works, but not for me. If there's nothing immediately wrong with this approach, I'll try a minimal example. As the game does use scrolling in all directions, so maybe that is affecting it. Anyways, thanks for your time. Link to comment Share on other sites More sharing options...
NoxBrutalis Posted July 22, 2018 Author Share Posted July 22, 2018 SOLVED AT LAST Im an idiot really as I think I read a post about this recently, but Im guessing a group is considered a container? I saw someone say that containers wipe set data from gameobjects when you add them to the container. This is definitely the case with group, though I'm wondering if this is expected behaviour? Im not sure as many people would spot it, as most people seem to have their players as standalone, but in my project the player is in a group with other friendly a.i sprites. So basically, if you add a sprite to a group after having set : this.player.setCollideWorldBounds(true); this.player.onWorldBounds = true; then its as if you never set it. So you either have to set them to true again, or set them to true after adding them to the group. There's possibly a way to set such properties on the group as a whole, but I don't know it. Anyways, so if your world bounds aren't working, check the order in which you initialise some of these properties in relation to when you add the sprite to a group etc. Pavel Mishin 1 Link to comment Share on other sites More sharing options...
Pavel Mishin Posted January 21, 2019 Share Posted January 21, 2019 Realy strange, all the more so only the `body.collideWorldBounds` is resets to default value, but `body.onWorldBounds` not... Link to comment Share on other sites More sharing options...
AndreasBU Posted December 11, 2020 Share Posted December 11, 2020 Thank god I found this thread. :-) NoxBrutalis, you saved me many hours. Link to comment Share on other sites More sharing options...
Recommended Posts