Jump to content

Shrinking rectangle graphic width is also shrinking / hiding graphic lineStyle


Recommended Posts

I'm setting the starting width of the blueBar rectangle based on how long a chord needs to be held. Then I decrease the width of the blueBar in the game loop:

const holdBar = new PIXI.Container();

let blueBar = new PIXI.Graphics();
    blueBar.lineStyle(2, 0x006ba6);
    blueBar.drawRect(0, 0,
           8 * (howLongDoesTheChordLastInMs / 16.67) - 50
containers.current.holdBar.children.forEach(blueBar => {
   console.log("my linestyle is:", blueBar.lineWidth);
   if(blueBar.x <= 100){
      blueBar.width = blueBar.width - 8;
      blueBar.x = blueBar.x - 8;


The result is that the lineStyle is getting chopped off even though the console.log still shows a lineWidth value of 2.


My guess is that the lineStyle is getting hidden by the container, or that graphics don't like having width dynamically changed in the game loop. 

Thank you for any advice on how to fix this! ?

Link to comment
Share on other sites

setting width is actually changing scale. Unlike Flash, PixiJS doesnt have auto-scaled lines, lineWidth works in local coordinates, so vertical lines become very thin if your scale is small. If you have only a few bars (20 or so) you can just clear() them and refill again with the other drawRect width param. Judging by your labels that's the case :)

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