Reputation: 330
I just started using Corona SDK. And learning how to make apps with it. For example i am using:
local myRectangle = display.newRect( 0, 0, 150, 50 )
myRectangle.strokeWidth = 3
myRectangle:setFillColor( 0.7 )
myRectangle:setStrokeColor( 1, 0, 0 )
When i use this it will look like this on my phone
When i am using this code:
local myRectangle = display.newRect( 77, 27, 150, 50 )
myRectangle.strokeWidth = 3
myRectangle:setFillColor( 0.7 )
myRectangle:setStrokeColor( 1, 0, 0 )
Then it will looks like this on my phone:
It looks like the offset is not good. Does anybody know how to fix this problem?
Upvotes: 1
Views: 114
Reputation: 652
At default, anchor point is in center of object. So if you set
myRectangle.x = 0
myRectangle.y = 0
center of the object will be at 0, 0. To change it, set anchors to 0, 0 (top left)
myRectangle.anchorX = 0
myRectangle.anchorY = 0
Upvotes: 2
Reputation: 1036
Whenever I make objects, I always set the x and y to 0 in the actual API. Then I do this after I create my object:
myRectangle.x = display.contentWidth/2
myRectangle.y = display.contentHeight/2
Hopefully this helps.
Upvotes: 1