How do I get text to center regardless of window size?

Get help using Construct 2

Post » Wed Mar 22, 2017 2:33 pm

Hey there!

I've changed my window size so that it can display full-screen regardless of window size, however I've now run into an issue. I initially had an action that would generate a piece of text that would display at the center of the screen. Since the screen size has changed, however, I need a way to have my piece of text positioned at the center of the screen. How would I go about doing this?

My initial action was System: Create object (text) on layer 2 (the HUD layer--this layer doesn't move regardless of anything happening in-game) at (275, 400)

EDIT: I've already tried examples such as WindowWidth/Height, self.Width/Height, Anchoring, etc., all of which to no avail.
B
5
Posts: 8
Reputation: 241

Post » Wed Mar 22, 2017 4:33 pm

Try (ViewportRight(0)-ViewportLeft(0))/2, (ViewportBottom(0)-ViewportTop(0))/2, where (0) is replaced by your background layer.

Although... the position shouldn't actually change even if you resize your window if you are using fullscreen in browser scaling, while parallax 0 takes care of in game scrolling.
Mistakes were made.
B
53
S
27
G
114
Posts: 1,695
Reputation: 64,438

Post » Wed Mar 22, 2017 5:36 pm

@oosyrag Yeah, no dice. Just ends up in the top-right corner.

The issue with my original code was also that it would spawn only at one place. So if I went to an area that wasn't where the text would show up, the text wouldn't follow me and end up on the screen where it needs to be.
B
5
Posts: 8
Reputation: 241

Post » Wed Mar 22, 2017 6:07 pm

Brawlitup99 wrote:@oosyrag Yeah, no dice. Just ends up in the top-right corner.

The issue with my original code was also that it would spawn only at one place. So if I went to an area that wasn't where the text would show up, the text wouldn't follow me and end up on the screen where it needs to be.


Is there a box in your CAPX using SCROLL_TO behavior?
Just set your Text at a distance relative to the box.
Image Image Image
B
32
S
12
G
27
Posts: 761
Reputation: 17,244

Post » Wed Mar 22, 2017 6:38 pm

@MPPlantOfficial I don't know how I would go about doing that. Do I use "set to another object?"

Another issue I see is that I plan to have areas that don't have the scroll_to box. Is there a way to set it up for those areas? Do I make another box?
B
5
Posts: 8
Reputation: 241

Post » Wed Mar 22, 2017 6:49 pm

Brawlitup99 wrote:@MPPlantOfficial I don't know how I would go about doing that. Do I use "set to another object?"

Another issue I see is that I plan to have areas that don't have the scroll_to box. Is there a way to set it up for those areas? Do I make another box?


What is the origin and sweet spot of your textbox anyway?

Maybe instead of: (ViewportRight(0)-ViewportLeft(0))/2, (ViewportBottom(0)-ViewportTop(0))
Try (ViewportLeft(0), ViewportTop(0) )
Image Image Image
B
32
S
12
G
27
Posts: 761
Reputation: 17,244

Post » Wed Mar 22, 2017 6:55 pm

Without seeing an example of your situation, it is hard to tell you what went wrong, but here is a bare bones example of what I am guessing you are trying to do.

https://www.dropbox.com/s/4rw2x1tsvm3nz ... .capx?dl=0
Mistakes were made.
B
53
S
27
G
114
Posts: 1,695
Reputation: 64,438

Post » Wed Mar 22, 2017 7:52 pm

@MPPlantOfficial Tried it. Now it's off the screen entirely. :/

@oosyrag That's exactly what I'd like to do. Unfortunately, for some reason, it doesn't do that.
B
5
Posts: 8
Reputation: 241

Post » Wed Mar 22, 2017 7:57 pm

@brawlitup99 does it have an anchor on it? cuz that can throw off what you are trying to do ...
B
27
S
5
G
1
Posts: 33
Reputation: 1,447

Post » Wed Mar 22, 2017 8:08 pm

Mubot wrote:@brawlitup99 does it have an anchor on it? cuz that can throw off what you are trying to do ...

No, got rid of the anchor after trying to work it.
B
5
Posts: 8
Reputation: 241

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 35 guests