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

0 favourites
  • 12 posts
From the Asset Store
Get Ready for the New Wave of "Bottom Screen" Games!
  • 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.

  • 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.

  • 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.

  • 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.

  • 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?

  • 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) )

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

  • 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.

  • Brawlitup99 does it have an anchor on it? cuz that can throw off what you are trying to do ...

  • 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.

  • 1. Make sure your hud layer is parallax 0,0

    2. Make sure your text object is being created on your hud layer

    3. Make sure your viewport expression references the correct layer

  • OK I figured it out. I messed with the scrollx and scrolly expression to get the text where I needed it to be.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)