ZYandu

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.beginFill(0xffffff);
    blueBar.drawRect(0, 0,
        Math.floor(
           8 * (howLongDoesTheChordLastInMs / 16.67) - 50
        ),
        10
    );
    holdBar.addChild(blueBar);    
containers.current.holdBar.children.forEach(blueBar => {
   console.log("my linestyle is:", blueBar.lineWidth);
   if(blueBar.x <= 100){
      blueBar.width = blueBar.width - 8;
   }
   else{
      blueBar.x = blueBar.x - 8;
   }
}

1573761067_ScreenShot2019-04-08at2_08_52PM.png.108baa206b0fac8279b6563bd7bc5cd5.png

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

1149045783_ScreenShot2019-04-08at1_51_39PM.thumb.png.c45b311c151c08651e12b4b2b68b4594.png

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! 😁

Share this post


Link to post
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 :)

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.

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

  • Recently Browsing   0 members

    No registered users viewing this page.