Incorrect width measurement of vector objects

2 replies [Last post]
Matthew Pringle
User offline. Last seen 3 weeks 3 days ago. Offline
Joined: 23 Feb 2010

1
2
3
4
5
6
7
local joystick = display.newGroup()
joystickOuter = display.newCircle( 60 , 60 , 59 )joystickOuter:setFillColor( 45 , 66 , 72 )
joystickOuter.strokeWidth = 2
joystickOuter:setStrokeColor( 183 , 237 , 254 )
joystick:insert( joystickOuter )
joystick.joystickOuter = joystickOuter
print(joystickOuter.width)

this width should be 120px but is reported as 122. Measuring / counting pixels on screen shows there are 120 in width

Replies

Tom
User is online Online
Ansca Staff
Joined: 13 Jul 2010

Matthew,

I believe the extra pixels comes from the stroke width. The documentation for object.strokeWidth property says, "Note that stroke widths are broken up to inner and outer parts."

-Tom

Matthew Pringle
User offline. Last seen 3 weeks 3 days ago. Offline
Joined: 23 Feb 2010

Hi Tom

Please run the demo or look at the code and do the math.

Radius of 59 pixels, gives object of 118px wide.

Adding a 2px stroke adds 1 px to either side, the outer part of the stroke.

This adds up to 120 px wide. Measuring a screen capture in a paint app will show the object is 120 px wide.

Asking corona the width gives 122px, doesn't seem right to me

Viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.