DisplayObject has different settings than foreseen

Hello!

have you ever tried this:

 local VectorObject = display.newRect(5,60, 70,70);
 VectorObject.strokeWidth = 1;
 VectorObject:setStrokeColor(222,0,0,128);
 VectorObject:setFillColor (64,64,64);
 print("Geometry = "..
 VectorObject.width.."\*"..VectorObject.height.."@"..
 VectorObject.x.."\*"..VectorObject.y
 );

Try this code (in the simulator with attached terminal) and look at the output - it will be

Geometry = 74\*74@40\*95

rather than

Geometry = 70\*70@5,60

Is that correct? [import]uid: 4331 topic_id: 975 reply_id: 300975[/import]

It seems that ANSCA’s magical scaling feature caught you. [import]uid: 5712 topic_id: 975 reply_id: 2219[/import]

This isn’t scaling. Here’s what’s going on:

(1) display.newRect sets x,y position using (top,left), which is (5,60) here. But the default registration point of any display object is the CENTER of the object, so unless you change its registration point, all further access to (x,y) is assumed to be the center of the object, not its top left corner.

(2) Adding a stroke makes an object larger. Specifically, the stroke will center on the object boundaries, but will snap OUTWARDS to the next whole pixel (otherwise odd-pixel stroke widths would be fuzzy). So a 2-pixel stroke will add a row of pixels inside and a row outside, but a 1-pixel stroke will simply add a row to the outside.

If you remove the stroke from the case above, you will see that it goes back to reporting a width and height of (70,70) – I just tested this myself.

However, it seems like the correct result with this 1-pixel stroke should be (72,72) rather than (74,74). Also, I just tested a variety of other stroke widths, and the same thing happens: the result is 2 more than what it seems like it should be. So I’m logging this latter part as a bug. [import]uid: 3007 topic_id: 975 reply_id: 2227[/import]

Thanks for this explanation!

Could you please also update your documentation (which mentions neither the fact, that a “strokewidth” modifies the size of an object nor the “registration point” of a rectangle)

B.t.w: what is the “registration point”? Is it the “reference point”? Or s.th. else?

Again, an update of the documentation would be useful!

Thanks in advance for your effort!

Kind regards,

Andreas Rozek [import]uid: 4331 topic_id: 975 reply_id: 2228[/import]