Jump to content

How does drawing graphics works?


spinnerbox
 Share

Recommended Posts

i wrote this utility function to save some space:

drawRect(graphics, x, y, width, height, bSize, bColor, bAlpha, fColor, fAlpha) {
    var rect = gameObject.add.graphics(x, y);

    rect.lineStyle(bSize, bColor, bAlpha);
    rect.beginFill(fColor, fAlpha);
    rect.drawRect(0, 0, width, height);
    rect.endFill();

    graphics.addChild(rect);

    return rect;
}

The graphics parameter is a top level graphics object.

My question is, at the call rect.drawRect(0, 0, width, height), is the rectangle drawn at (0, 0) in the rect world or is (0, 0) in the graphics object aka top level container?

Link to comment
Share on other sites

If I understand well, first rect has (x, y) coordinates, then it is (0, 0) in gameObject.world.

And then when I add it to graphics it is at (0, 0) in the graphics object?

Haha, I really need to test this out :)

EDIT: At first the rect is at (x, y) inside gameObject.world and when it is added into its parent graphics object, the shift in both x and y directions stack up, meaning, rect now will look shifted with coordinates (parentGrX + rectX, parentGrY + rectY).

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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