Jump to content

How can I visualise re-writing pixi v4's `graphics.addHole()` method?


9bar
 Share

Recommended Posts

Hey ?

 

I am trying to update a game, it's essentially a map and it's essentially a `number[][][]`.

 

This is not real data, but a good example.

 

const myMap = [
   [
      [16383, -3784, -13, -12],
   ],
   [
      [-251, -91, -5, -2, 3],
      [4483, -115, 0, -5],
   ]
]

 

Lets look at the current code which is v4.

 

        pixiTextureByName.polygons = new Graphics();
        pixiTextureByName.polygons.beginFill();

        let countTotal = 0;
        let lastX = 0;
        let lastY = 0;

        let points: number[];

        for (let itrA = 0; itrA < myMap.length; itrA++) {
            let counterA = 0;
            for (let itrB = 0; itrB < mapResponse[itrA].length; itrB++) {
                points = [];
                for (let itrC = 0; itrC < mapResponse[itrA][itrB].length; itrC = itrC + 2) {
                    const curX = mapResponse[itrA][itrB][itrC] + lastX;
                    const curY = mapResponse[itrA][itrB][itrC + 1] + lastY;
                    points.push(parseFloat(curX.toString()), -parseFloat(curY.toString()));
                    lastX = curX;
                    lastY = curY;
                    countTotal++;
                }
                pixiTextureByName.polygons.drawPolygon(points);
                if (0 != counterA) {
                    pixiTextureByName.polygons.addHole();
                }
                counterA++;
            }
        }
        pixiTextureByName.polygons.endFill();
        
        pixiContainerByName.map.addChild(pixiTextureByName.polygons);
        pixiContainerByName.map.mask = pixiTextureByName.polygons;

 

Looking at the following page:

 

https://github.com/pixijs/pixijs/wiki/v5-Migration-Guide

 

I have tried every combination (that seems logical) to use `beginHole` and `endHole` between the polygon points to failed results.

 

Anyway I appreciate this is incredibly specific so no worries if no one has the time to check it out  :)!

Kind regards.

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