Coordinate issues

1 reply [Last post]
jtokash
User offline. Last seen 6 weeks 2 days ago. Offline
Joined: 19 Feb 2010

This code tries to put both the red and the blue block at x=60. It doesn't. The red block's x is actually 100 according to blahrect.x. Meanwhile, although the blue block says x=60, it looks on screen more like 20.

1
2
3
4
5
6
redblock = display.newRect(60,40,80,20)
redblock:setFillColor(255,0,0)
blueblock = display.newRect(40,2,80,20)
blueblock:setFillColor(0,0,255)
transition.to(blueblock,{time=1000,x=60})
transition.to(blueblock,{time=1000,y=70})

Replies

evank
User offline. Last seen 1 year 4 weeks ago. Offline
Joined: 16 Sep 2009

Note that the default registration point of a Corona display object is its center. For example, if you create a rectangle with display.newRect( 10, 10, 300, 300), then its initial position will be x = 160, y = 160.

If you would like to position an object by its top left corner (for example), you can change its registration point like this:

object:setReferencePoint( display.TopLeftReferencePoint )

For more information, see "Display Objects: Common Object Methods" in the API Reference (page 50 of the current-edition PDF).

Viewing options

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