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

Get help using Construct 2

Post » Sat Aug 06, 2016 8:17 pm

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?
B
3
Posts: 1
Reputation: 177

Post » Sat Aug 06, 2016 8:37 pm

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
B
4
S
1
G
3
Posts: 2
Reputation: 1,804

Post » Sun Aug 07, 2016 4:55 am

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
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
40
Posts: 3,032
Reputation: 30,499


Return to How do I....?

Who is online

Users browsing this forum: minigame, R0J0hound, Yahoo [Bot] and 24 guests