Center object withing an object

I have 2 rectangles evenly sized on each side of scene and want to center an object in each rectangle. I used the center object command and named each rectangle but the second one keeps overlapping the first.

I used center with Screen1.Width()/2 and Screen1.Height()/2 but when I do this for screen2 on the right side it overlaps the first one on the left. I had it working and deleted something and now its not working even though

Any help is appreciated…

Use instead CameraCenterX() CameraCenterY()

Now i am not sure i get you
You want to center them both in same position so they look like one rectangle?
If so then what i wrote still stands

Your problem is that the origin, which is where the box is drawn at, is located at the top left of the image. So you need to offset the position by half the rectangle width or height. To do this, use the following to get the x & y positions for the rectangles:

ScreenWidth()/2 - recatngle1.Width()/2 and
ScreenHeight()/2 - recatngle1.Height()/2

Alternatively, open each object in the object editor, click on “Edit points” and set the origin to the same position as the centre. Now if you place the rectangle objects at ScreenWidth()/2, ScreenHeight()/2, they’ll both be centred, one within the other one.

no I have a split screen with one box on one half and another on the other half and want to load an object into the middle of each box. trying all these different things and I either fix the box and get the object inside wrong or the box doesn’t resize with window.

Thanks for the feedback

Thanks, I tried it but something isn’t right. I will try again later and maybe just start over. This is like the main structure of what I’m trying to accomplish and if I can’t do it I may just do some more research or learn more or something. Very frustrating working on simple boxes this long. Thanks for the help.

If these objects are same objects then you need to give them instance variables

You never wrote either of those things - split screen, boxes (i.e. 3D) or resizing - in any of your previous posts in this thread. Rectangle and scene mean 2D and one screen.

Can you start again, and describe exactly what you’re trying to achieve?

I will try to explain a bit, I want 2 equal sides, one for player 1 and the other for player 2 (either computer or online). Player 1 loads in one side and player 2 in the other and if I resize the game window each side changes in proportion to screen. So player one does something to player 2, he sees it on that screen and if player 2 does something to player one he sees it on his screen.

I think if I can at least figure the sides out I can add in and get the other parts correct but this is the structure I’m trying to create. this is why I want to rectangular objects to house each player object and resize with the screen. Hope this gives some clarity.

Thanks for the help,

So do you mean that all the objects in one of the split screens are shown in the viewport? And would you zoom in/out to fit all the objects in the viewport? And apply that zoom to both viewports?

Is the game 2D or 3D? Because that makes a big difference to any follow up answers.

2d(maybe 3d in the second) game with just a player object on each side in the same place. just want to put the players even on each side and if the window resizes everything stays the same. just a player/oject in the center on one side and another on the other side. no zoom or anything, just one object for each that gets actions taken on it, everything will fit within the screen(maybe zoom forward or backward if some action is taken but not at first).

Thanks for the insight and help… If I can just figure out this structure I feel I can put the rest inside.

If you’re using the GDevelop split screen example, then you’re centring the camera on an object in the scene. So either use that object to place the rectangles, or use @ZeroX4’s suggestion of CameraCenterX() & CameraCenterY() to place the rectangle