It looks like you're new here. If you want to get involved, click one of these buttons!
I'm really enjoying using orx so far. Hopefully this is an easy one - I've set my Display to fullscreen. I then set my camera Frustum width and height based on that. I'd like to be able to set the position of objects relative to those dimensions...for example, to place a blocking pillar at the right edge of the screen. For now I've hard coded positions to look ok on my laptop.
The various ways I've tried to specify this in the Position= line of an object don't seem to work. Assuming this can be done in the ini file, how would you set an object position's x value at the screenwidth - 100 (for example)
thanks again for all the help!
Hi Funemaker, you can have a large empty object the same size as your viewport, and then have your objects as relative parent positioned inside the object. Then your position range will be 0.0 ... 1.0.
And the size of the screen won't matter anymore.
Thanks @sausage, this makes sense. I've been trying to get it to work following the "UseParentSpace for Relative Object Positioning and Scaling" tutorial. Seems very simple but I haven't had success yet, my object always shows up at 0,0 when I do it this way.
Will try again this weekend and see what is wrong.
Ah ok. I must have done something not so clear on that tutorial then. Oh and sorry... it's -1.0 to 1.0. So to go into negative range.
That's not entirely correct though, the viewport's size is in screen space, not world space, and if your camera's frustum isn't the same size as the screen, that won't work. However there's a simpler way, I'll come back to it at the end of this post.
First things, you don't need to see the camera's frustum to match the display's screen resolution. If you do so, you will end up with different aspect ratio and very different sizes across different machines. This is going to be more of a nightmare to use than anything else. I'd recommend defining a camera size that matches your default target resolution, and then let the viewport do any scaling for you if need be.
Now regarding your main question, you can set objects as children of a camera. Which in turn will enable you to position/scale them relatively to the camera. That's very handy for things like static backgrounds or UI elements.
For this to work, you need to set the
ParentCameraproperty on your object (and the camera needs to be created before the objects, obviously).
Then you have a choice of using the
UseParentSpaceproperty. What this does is that instead of using regular units, everything will be relative to the camera's frustum size. By default,
UseParentSpaceis set to
true, which means both position and scale will be expressed in "camera units", 1 meaning the whole length of the frustum on that axis.
Let's take some examples. Let's assume our camera is called "MyCamera". Let's see how we would set a background object that will be scaled to match the entire camera's frustum:
Let's now say we want to have a ceiling object that aligns exactly with the top of our camera and that the object's entirely visible in the camera (ie. the object's top aligns with the camera frustum's top). Let's also say we want it to have a scale of twice its default size but won't adapt to the camera (ie. we want the position to be relative to the camera's size but not the scale):
Note that relative position on one axis goes from -0.5 to 0.5, as 1 means the whole length of the camera's size on that axis (some might have expected to use -1 to 1 but that wouldn't be consistent with the fact that 1 = the whole size). Also note that if you resize your camera later on, the objects using
UseParentSpacewon't re-adjust their scale/position automatically, the
UseParentSpaceonly affects the position/scale values at creation.
Let us know if you need more details!
Now to cover your specific question (Pillar at screenwidth -100), you'll need to either use
UseParentSpaceand then find what 100 is in parent space (ie. 100 / FrustumWidth), or simply use plain value if you know what the camera's FrustumWidth is. Now if you want your pillar to fit entirely in the screen but be right at the edge (like our ceiling above), you won't need to know the FrustumWidth at all.
Here are the three variants (assuming vertical centering):
Note that you can also do the maths yourself and hardcode the values instead of using commands.
Thanks @sausage, I think maybe last night it was working, but I was setting my pillar x position to 0.1. That might be why I thought it was still showing in the center when I expected it closer to the left border. And the tutorial itself worked for me as expected, but just not when I tried to apply it to my own project and objects.
And thanks @iarwain, that is a very comprehensive answer, thanks for taking the time. I'm off to work shortly so can't try anything until later tonight probably. Will report back if I have any trouble.
Ok, I quickly got it working before heading out. One thing that I got a little confused on is that I'm scaling my object to 0.5. I had this line before the UseParentSpace = position line and I think it must have been scaling to the camera's size. Once I moved the Scale= line after the UseParentSpace line it works completely as expected. Thanks!
That's weird as the order in config has absolutely no impact at all (all entries are stored upon loading). Are you sure there wasn't something else, like a typo?
In any case, I'm glad it's now working.
I'll check it again later tonight...I thought that was strange for the order to have an impact.
My bad! Thanks for pointing that out...indeed the ordering has no consequence!...so I was able to retrace my tracks with undo in Visual Studio since I had left the file open this morning. Looks like I originally had UseParentSpace = both rather than UseParentSpace = position. Using "both" was causing unwanted scaling of my object. I apparently changed that AND the ordering of the property lines at the same time and made a bad assumption about which change was having an effect.
That's what I get for trying to "quickly" try something on my way out the door. Sorry for the confusion!
No worries, I'm glad you found the reason, this way I don't have to hunt for a bug that doesn't exist!