How can I center text?

Get help using Construct 2

Post » Sat Dec 17, 2011 2:22 pm

I have two text boxes (CoverTitle and CoverDesc) and a tiled background.
On start of layout I do:

CoverTitle => Set position to ((LayoutWidth-CoverTitle.Width)/2, 32)

CoverDesc => Set position to ((LayoutWidth-CoverTitle.Width)/2, CoverTitle.Y+CoverTitle.Height+10)

[ Replacing with "CoverDesc => Set position to ((CoverTitle.X, CoverTitle.Y+CoverTitle.Height+10)" does the same ]

TiledBackGround => Set size to CoverTitle.Width, CoverTitle.Height

TiledBackground => Set position to CoverTitle

[ Replacing with "TiledBackground => Set Position to )CoverTitle.X, CoverTitle.Y)" does the same]

The described method DOES NOT center text. Instead, the window is divided in two halves. CoverTitle is centered on first half of the window, and CoverDesc and TiledBackground are centered in the other half.

Replacing LayoutWidth with WindowWidth seems to do the same. I've tried with Fullscreen "scale mode" also.

Is this a bug?
B
39
S
11
G
5
Posts: 132
Reputation: 8,228

Post » Sat Dec 17, 2011 2:40 pm

Use layoutwidth/2 - textbox.width/2
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Sat Dec 17, 2011 2:47 pm

According to distributive property, ((A/2)-(B/2))=(A-B)/2

Despite of that, I've also tried it.
B
39
S
11
G
5
Posts: 132
Reputation: 8,228

Post » Sat Dec 17, 2011 2:48 pm

Indeed, my bad.
Post your capx please.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Sat Dec 17, 2011 2:55 pm

Last edited by Yann on Sun Sep 14, 2014 10:46 pm, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sat Dec 17, 2011 3:47 pm

Yann,
Your file works on my computer. But the same does not work when applied to my objects (I tried positioning the focus at the center before I used the other approach).

I'm sure I've done something wrong when inserting the objects in the layout, as I did last time. I'll post my capx, as Kyatric suggests.

http://apagada.com/varios/labe3_alpha2/labe3.capx
B
39
S
11
G
5
Posts: 132
Reputation: 8,228

Post » Sat Dec 17, 2011 5:48 pm

there ya go
centering.capx

Basically you had a useless behavior on the title text (anchor)
And you have to scroll to the center of the layout for your object to be centered.
And do that every tick in case people resize the window.
Last edited by Yann on Sun Sep 14, 2014 10:46 pm, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sun Dec 18, 2011 3:51 pm

If I can't use pin, how can I make sure second text is always moved with first text?
B
39
S
11
G
5
Posts: 132
Reputation: 8,228

Post » Sun Dec 18, 2011 4:04 pm

pin is just a behavior that does the same thing as

[code]system : every tick
    -> secondText: set position to firstText[/code]

and nobody said you can't use pin
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sun Dec 18, 2011 4:13 pm

Now I know how to center text and I know how to get overall width (it took me a month to realize that "hanged" floating window appearing sometimes over Construct 2 was the syntax hint), I can add credit pages to all my creations.

I am thinking about posting my labrynth generator as an "example", since it is an example on how to make complex conditions using events. What do you think about it?

Do you think I should post it on the examples section of Scirra Arcade, or in the C2 tests section of "Construct 2 General"?
B
39
S
11
G
5
Posts: 132
Reputation: 8,228

Next

Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, armaldio, plinkie and 15 guests