Jump to content

Scaling sub-container in PixiJS doesn't preserve MatterJS bodies


Recommended Posts

I'm using Matter.js as my physics engine and Pixi as my renderer and under normal circumstances I've been able to get them to work smoothly.  However, I'm trying to do something where all of the objects *except* the player character are scaled down to look like the character is now above them.  The scaling works visually in Pixi, but I can't get the bodies from Matter.js to go with it, so there are these "ghost objects" that I can't see but if collide with them then the scaled down objects will be moved.


Does anyone have any tips for how to resolve this?  Let me know if I need to post a gif if that would help explain the problem.

Link to comment
Share on other sites

If the problem is cumulative scaling, what about storing scale factor and scaling by the reciprocal of the old scale factor before you scale by the new factor? That's the only thing I can think of but maybe the way they scale is too different

Link to comment
Share on other sites

This is in the game loop:


below.scale.x *= .5
below.scale.y *= .5
for (let i = 0; i < below.children.length; i++){
      Body.scale(map, below.scale.x, below.scale.y, { x: 0, y: 0 })


below is a PIXI container and map is an array of Matter bodies

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.

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.


  • Recently Browsing   0 members

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