Jump to content

P2 Physics- static sprites still move


J4G
 Share

Recommended Posts

I'm creating a game where, by necessity, each of my tiles exists as a sprite within a group. They all use P2 Physics for collisions. I'm careful to set each sprite to static, and then configure them like so
 
         this.sprite.body.setRectangle(TILE_WIDTH, TILE_HEIGHT)
         this.sprite.body.static = true;
 
         this.sprite.body.x = this.x * TILE_WIDTH + (TILE_WIDTH / 2);
         this.sprite.body.y = this.y * TILE_HEIGHT + (TILE_HEIGHT / 2);
 
But the locations of the bodies are ever so slightly off, usually by around .0000001, and it looks like this error is applied on every update cycle in spite of my efforts.

2yPUnVv.png
 
Now you wouldn't think such a minor change would affect things, but it actually leads to rounding errors causing vertical black lines between tiles. Is this a bug, or are there changes I can make to my code to resolve this?
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...