Sign in to follow this  

SOLVED issue with world bounds collision

Recommended Posts

Hi everyone, I'm trying to implement world bounds and can't get it to work.

Here's how I'm doing it:, 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.onWorldBounds = true;'worldbounds', function(body){
    console.log('hello from the edge of the world', body);

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, 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.

Share this post

Link to post
Share on other sites


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.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.

Share this post

Link to post
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.

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.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.