Mobile screen is cropping image

If I put a code like this, in coordinates 0,0, my rectangle will appear cropped at top-left of the mobile screen.

local star = display.newRect(0, 0, 40, 40)

How can I fix this problem? I mean, I want that coord 0,0 being the top-left of the viewable area, so that my rectangle will not appear cropped. [import]uid: 123516 topic_id: 32279 reply_id: 332279[/import]

The reference point of the display object is at the centre of the object instead of top left.

Change the reference point to TopLeft and reinitialise the position.

local star = display.newRect(0, 0, 40, 40) star:setReferencePoint(display.TopLeftReferencePoint) star.x = 0 star.y = 0 [import]uid: 33275 topic_id: 32279 reply_id: 128405[/import]

Most Corona display objects are based on X, Y being the center of the object. You can solve this in one of two ways:

star = display.newRect(0,0,40,40)  
star.x = star.width / 2  
star.y = star.height / 2  

which is kind of stupid looking… I of course would have just done x=20 and be done with it. Or the more practical way is to do this:

star = display.newRect(0,0,40,40) star:setReferencePoint(display.TopLeftRefererencePoint) star.x = 0 star.y = 0 [import]uid: 19626 topic_id: 32279 reply_id: 128406[/import]

The object should not be chopped because when a newRect is created, it’s created with a TopLeft reference. So 0,0 will position the top left corner of the rect at the top left of the screen. It may look chopped if you have the status bar visible. You can turn off the status bar as follows:

display.setStatusBar(display.HiddenStatusBar)

Once the rect object has been created, the reference point is now located in the center of the object so any changes to x and y will be relative to the object center. This can be changed using display.setReferencePoint. [import]uid: 7559 topic_id: 32279 reply_id: 128463[/import]

Good to know Tom. [import]uid: 19626 topic_id: 32279 reply_id: 128482[/import]

The reference point of the display object is at the centre of the object instead of top left.

Change the reference point to TopLeft and reinitialise the position.

local star = display.newRect(0, 0, 40, 40) star:setReferencePoint(display.TopLeftReferencePoint) star.x = 0 star.y = 0 [import]uid: 33275 topic_id: 32279 reply_id: 128405[/import]

Most Corona display objects are based on X, Y being the center of the object. You can solve this in one of two ways:

star = display.newRect(0,0,40,40)  
star.x = star.width / 2  
star.y = star.height / 2  

which is kind of stupid looking… I of course would have just done x=20 and be done with it. Or the more practical way is to do this:

star = display.newRect(0,0,40,40) star:setReferencePoint(display.TopLeftRefererencePoint) star.x = 0 star.y = 0 [import]uid: 19626 topic_id: 32279 reply_id: 128406[/import]

The object should not be chopped because when a newRect is created, it’s created with a TopLeft reference. So 0,0 will position the top left corner of the rect at the top left of the screen. It may look chopped if you have the status bar visible. You can turn off the status bar as follows:

display.setStatusBar(display.HiddenStatusBar)

Once the rect object has been created, the reference point is now located in the center of the object so any changes to x and y will be relative to the object center. This can be changed using display.setReferencePoint. [import]uid: 7559 topic_id: 32279 reply_id: 128463[/import]

Good to know Tom. [import]uid: 19626 topic_id: 32279 reply_id: 128482[/import]