Corona SDK的偏移量不好。

我刚刚开始使用 Corona SDK,并学习如何使用它制作应用程序。例如,我正在使用以下代码:

local myRectangle = display.newRect( 0, 0, 150, 50 )
myRectangle.strokeWidth = 3
myRectangle:setFillColor( 0.7 )
myRectangle:setStrokeColor( 1, 0, 0 )

当我在手机上使用它时,它会看起来像这样

enter image description here

当我使用以下代码时:

local myRectangle = display.newRect( 77, 27, 150, 50 )
myRectangle.strokeWidth = 3
myRectangle:setFillColor( 0.7 )
myRectangle:setStrokeColor( 1, 0, 0 )

然后它在我的手机上看起来像这样:

enter image description here

看起来偏移量不好。 有人知道如何解决这个问题吗?

点赞
用户825481
用户825481

每当我制作对象时,我总是在实际的 API 中将 x 和 y 设为 0。然后,在我创建对象后,我会执行以下操作:

myRectangle.x = display.contentWidth/2
myRectangle.y = display.contentHeight/2

希望这能帮助到您。

2014-02-22 21:07:43
用户1925928
用户1925928

默认情况下,锚点在对象的中心。因此,如果您设置如下代码:

myRectangle.x = 0
myRectangle.y = 0

对象的中心将位于 0, 0。如需更改,请将锚点设置为 0, 0(左上角),示例如下:

myRectangle.anchorX = 0
myRectangle.anchorY = 0
2014-02-23 08:03:04