How do I position all the multiple object at the center?

Get help using Construct 2

Post » Thu May 29, 2014 11:24 pm

Hi guys,

I've got this objects on my level layout selection, like lock and unlocked, I've been figuring out how I can automatically position them in the center if it will be viewed by different mobile screen devices?

Thank you in advance for the help.
B
48
S
14
G
20
Posts: 87
Reputation: 12,938

Post » Thu May 29, 2014 11:39 pm

@LaroTaio Not sure what you mean.

You can align objects simply by right-clicking the object and find the "Center horizontal" or "Center vertical" options. You can also use system expressions like "WindowHeight", "WindowWidth", "LayoutWidth", or "LayoutHeight" and divide them by 2 in your object positions.
yupenglee.com | @JustOnlyYu
B
14
S
3
Posts: 16
Reputation: 872

Post » Fri May 30, 2014 1:46 am

arthology wrote:@LaroTaio Not sure what you mean.

You can align objects simply by right-clicking the object and find the "Center horizontal" or "Center vertical" options. You can also use system expressions like "WindowHeight", "WindowWidth", "LayoutWidth", or "LayoutHeight" and divide them by 2 in your object positions.


I mean is like with html, you have 3 images horizontally aligned, when you insert the center tag code, what ever the screen size of the browser it will keep the 3 images at the center. that sort of thing is what I want to happen. coz when I view my game on other android screen devices specially with large width screen, all are objects are placed on the left side of the screen. I want my entire layout objects positioned at the center.
B
48
S
14
G
20
Posts: 87
Reputation: 12,938

Post » Fri May 30, 2014 2:57 am

@LaroTaio You could create an object that will act as a container for your 3 images. Then, that container will be centered in the layout/screen and the 3 images will be "pinned" to the container.
yupenglee.com | @JustOnlyYu
B
14
S
3
Posts: 16
Reputation: 872

Post » Fri May 30, 2014 6:00 am

@arthology

My windwo size is 640 by 480, I followed your instruction

You can align objects simply by right-clicking the object and find the "Center horizontal" or "Center vertical" options. You can also use system expressions like "WindowHeight", "WindowWidth", "LayoutWidth", or "LayoutHeight" and divide them by 2 in your object positions.


then I copied the position of the object from the properties window and paste it on the system expression LayoutWidth and LayoutHeight, I also tested it on the WindowHeight and WindowWidth expression, :( still the object is positioned at the upper left corner.

Image

Image
B
48
S
14
G
20
Posts: 87
Reputation: 12,938

Post » Fri May 30, 2014 8:25 pm

@LaroTaio

Divide the LayoutWidth or LayoutHeight by "2" , which will put the 'Sprite' object based on its "origin point" in the center of your layout, like this:
Sprite | Set position to (LayoutWidth/2, LayoutHeight/2)

Note: if your origin point is in the center of your object, then the object's center will be aligned with the layout's center. If your origin point is in the top left corner, then the object's corner will be aligned on top of the layout's center.

Here's what 'LayoutWidth/2' means: if you folded a piece of paper from the left edge all the way to the right edge and unfolded it, you'll get an vertical crease exactly in the middle of the paper with two equal left and right halves. You're essentially finding the layout's exact middle point along the x-coordinate (width-wise).

Here's what 'LayoutHeight/2' means: if you folded a piece of paper from the top edge all the way to the bottom edge and unfolded it, you'll get a horizontal crease exactly in the middle of the paper with two equal top and bottom halves. Now, you have the layout's exact middle point along the y-coordinate (height-wise).
yupenglee.com | @JustOnlyYu
B
14
S
3
Posts: 16
Reputation: 872

Post » Fri May 30, 2014 8:42 pm

Assuming these sprites are not supposed to be movable by the user (they are HUD sprites) you don't need to anchor or do any math for centering... just place your sprites on a layer with parallax set to 0,0 and they center them selves to the point you placed them.
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Fri May 30, 2014 9:50 pm

@arthology

Finally got it working, I thought of dividing the actual size of the window screen by two, but by 2 as you mentioned, silly me :lol: Now my next objective is aligning multiple objects at the center, I'll try the container thing you replied earlier. Also, I really appreciate your explanation on how centering object works in C2. Thank you so so much :D

@troublesum
Thank you for helping out as well, but these sprites are movable, they are objects for level selection to be exact there are 20 rows and 4 columns about 80 levels.
B
48
S
14
G
20
Posts: 87
Reputation: 12,938


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 5 guests