How do I place an object at the center of the screen

0 favourites
  • 3 posts
From the Asset Store
Forgotten Place - Melodic ambiance, background music, Synth
  • Hi,

    Total game dev noob here. I did the tutorial and I'm now playing a little bit with it. I want the game to have a game over text. I downloaded a free sprite font and I now have the text on the HUD layer. It goes visible when the player dies, but I have no idea how to set it's position to the center of the view.

    How do I do this?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • set position

    x - layoutwidth/4 (maybe 2)

    y - layoutheight/4 (maybe 2)

    or windowwidth, windowheight

    or just get the exact coordinates by placing the object where you want it to be and then set the coordinates as such when its actually created

  • You can also place it based on the current viewport - if your layout is really large and you have some scrolling going on, using layoutwidth and layoutheight won't work for placing it in the center of the players screen.

    You would need to do something like;

    Object.X = (viewportright("layername")-viewportleft("layername"))/2

    Object.Y = (viewportbottom("layername")-viewporttop("layername))/2

    Of course if your game is just a single screen then what Drasanas said would do the trick.

    ~Sol

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