Ending position of an object

Hi,

In Corona SDK, we specify x and y coordinate to show an object on screen. We can access x and y coordinate of an object by using object.x and object.y, it will return starting x and y of that object.

Is there any method which can show ending x and y position of an object in Corona SDK. [import]uid: 176766 topic_id: 33081 reply_id: 333081[/import]

Hi robustur3,

What do you mean by the “ending” x,y position? Do you mean, say, the x,y position after the object moves (due to, say, a transition.to)? Do you mean the lower right corner of the object? Or something else?

  • Andrew [import]uid: 109711 topic_id: 33081 reply_id: 131370[/import]

Hi Andrew,

Thanks for your response.

When we display an object screen. For example, display.newImage(“crateA.png”,80,150) will be displayed on (80,150) position. These values are the initial values of x and y coordinate, where the image will start displaying. I need the ending position of the image in the form of x and y coordinate.

[import]uid: 176766 topic_id: 33081 reply_id: 131372[/import]

OK, it sounds like by “ending” you mean the lower right corner of the object. In that case, try the following:

[blockcode]
local crate = display.newImage(“crateA.png”,80,150)

– Get upper left corner
local ulx, uly = crate.x - display.contentWidth/2, crate.y - display.contentWidth/2

– Get lower right corner
local lrx, lry = crate.x + display.contentWidth/2, crate.y + display.contentWidth/2
[/blockcode]

Since crate.x and crate.y represent the center of the object, subtracting or subtracting half of the width and height will get you the coordinates of the corners.

Hope this helps.

  • Andrew
    [import]uid: 109711 topic_id: 33081 reply_id: 131373[/import]

Many Corona display objects when you pass the X, Y as parameters, it assumes you want those to be the Top Left of the position, temporarily setting the reference point to display.TopLeftReferencePoint, after that accessing X and Y should give you the center reference point.

If you do:

obj = display.newImage(“image.png”)
obj.x = 80
obj.y = 150

Then the X and Y will be the center of the image. aukStudio’s code will give you the right coordinates for the top,left and bottom,right of the image. Personally I don’t like using passed parameters to position objects because I’m never sure when they are Center or TopLeft reference pointed. I always explicitly set the X and Y like I did above to make sure I’m setting the center (or I explicitly set a reference point).

[import]uid: 19626 topic_id: 33081 reply_id: 131382[/import]

Hi robustur3,

What do you mean by the “ending” x,y position? Do you mean, say, the x,y position after the object moves (due to, say, a transition.to)? Do you mean the lower right corner of the object? Or something else?

  • Andrew [import]uid: 109711 topic_id: 33081 reply_id: 131370[/import]

Hi Andrew,

Thanks for your response.

When we display an object screen. For example, display.newImage(“crateA.png”,80,150) will be displayed on (80,150) position. These values are the initial values of x and y coordinate, where the image will start displaying. I need the ending position of the image in the form of x and y coordinate.

[import]uid: 176766 topic_id: 33081 reply_id: 131372[/import]

OK, it sounds like by “ending” you mean the lower right corner of the object. In that case, try the following:

[blockcode]
local crate = display.newImage(“crateA.png”,80,150)

– Get upper left corner
local ulx, uly = crate.x - display.contentWidth/2, crate.y - display.contentWidth/2

– Get lower right corner
local lrx, lry = crate.x + display.contentWidth/2, crate.y + display.contentWidth/2
[/blockcode]

Since crate.x and crate.y represent the center of the object, subtracting or subtracting half of the width and height will get you the coordinates of the corners.

Hope this helps.

  • Andrew
    [import]uid: 109711 topic_id: 33081 reply_id: 131373[/import]

Many Corona display objects when you pass the X, Y as parameters, it assumes you want those to be the Top Left of the position, temporarily setting the reference point to display.TopLeftReferencePoint, after that accessing X and Y should give you the center reference point.

If you do:

obj = display.newImage(“image.png”)
obj.x = 80
obj.y = 150

Then the X and Y will be the center of the image. aukStudio’s code will give you the right coordinates for the top,left and bottom,right of the image. Personally I don’t like using passed parameters to position objects because I’m never sure when they are Center or TopLeft reference pointed. I always explicitly set the X and Y like I did above to make sure I’m setting the center (or I explicitly set a reference point).

[import]uid: 19626 topic_id: 33081 reply_id: 131382[/import]