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

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