Center text

Get help using Construct 2

Post » Tue Apr 10, 2012 11:28 pm

Hey, i've been trying to get this done for like 2 hours now, and i've read a bunch of forum posts that come close but none explains it the way i want it.

So here is what i want to do:
For example, i'd like a text saying something like 'copyright 2012' on the bottom center of a menu or splashscreen. How do I do that. I want to center the buttons in the menu as well for that matter...

Thanks for any help!
greets
B
3
Posts: 2
Reputation: 279

Post » Wed Apr 11, 2012 12:59 am



My preferred approach is to use WindowWidth and WindowWidth to arrange objects:

Set the text object's horizontal alignment to center in the properties panel and then in the event sheet, if you want the text object to be on the bottom center of the window:

On start of layout, set text object's position to:

x: (WindowWidth - self.Width)/2
y: WindowHeight - self.Height


This works for any object, not just text. If you wanted the object right in the middle of the screen both vertically and horizontally,

x: (WindowWidth - self.Width)/2
y: (WindowHeight - self.Height)/2

For the buttons, check out part 2 of my tutorial on Creating a Memory Match Game. It shows how you can arrange a layout of cards that resizes and rearranges if the window size changes, but the technique would work just as well for buttons.

EDIT: You can read about the Anchor behavior in the manual, but I don't think it works well for centering.

kittiewan2012-04-11 01:13:09
B
29
S
11
G
12
Posts: 281
Reputation: 11,868

Post » Wed Apr 11, 2012 10:07 am

Great, that's exactly what i needed. I don't know why I haven't found that solution before. Thanks

I tried using anchor before this, but that only works for keeping an object at the bottom, top, left or right not the center.

And thanks for the link to you're tutorial, that'll probably help me a good bit on my way.
B
3
Posts: 2
Reputation: 279

Post » Wed Apr 11, 2012 6:06 pm

@kittiewan OMG I'm sooo happy I click through these how do I's

I was trying to figure that out the other day.

x: (WindowWidth - self.Width)/2
y: (WindowHeight - self.Height)/2

I couldn't figure out how to center text or objects with command, I tryed WindowWidth/Hight, LayoutHight/Width etc.. but didn't succeed.

Thanks
B
27
S
11
G
1
Posts: 246
Reputation: 5,048


Return to How do I....?

Who is online

Users browsing this forum: mercuryus and 15 guests