AdamJones
AdamJones

Reputation: 601

adding objects to screen in corona sdk without defining x y coordinates? corona sdk

A very simple beginners question... I assume this must be possible....

How do you add objects to a screen in Corona (take simple standard widget items like buttons) in a way that they just appear below each other and so avoid having to give each item a "top" value that is relative to the top of the screen? Surely there is a way of doing this either automatically or referencing the previous object to place the next objects position?

I thought grouping items may assist with this but hasn't with my experiments so far.

Upvotes: 0

Views: 436

Answers (2)

Matthew Mellea
Matthew Mellea

Reputation: 89

You can use variables and information about other objects to define positions of buttons. Let's say you have an object, button1. You want another object, button2, to be 20 pixels above it.

button1.y = 45
print(button1.y)--You'll get 45.
button2.y = button1.y - 20--Remember that the origin (0,0) is at the top left. Subtracting 20 makes the object closer to the top.
print(button2.y)--You'll get 25.

X, Y coordinates can be defined by a combination of variables with mathematical operations. You can greatly speed up your code by defining many objects relative to one central object.

Upvotes: 1

Imdadul Huq Naim
Imdadul Huq Naim

Reputation: 364

button2.x=button1.x button2.y=button1.y+20 .... button3.x=button2.x+20 button3.y=button2.y+20

You can design this way, in this way you can set the relative position of the buttons. I hope it will help you.

Upvotes: 0

Related Questions