spinnerbox Posted September 2, 2016 Share Posted September 2, 2016 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 More sharing options...
Milton Posted September 2, 2016 Share Posted September 2, 2016 At rect.drawRect it uses gameObject, so (0,0) uses the x, y offset (it doesn't even know about your 'graphics' parameter). When you make 'rect' a Child of 'graphics', it adds the offset of 'graphics'. spinnerbox 1 Link to comment Share on other sites More sharing options...
spinnerbox Posted September 5, 2016 Author Share Posted September 5, 2016 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 More sharing options...
Recommended Posts