I'm currently playning around with the orx engine a bit. I'm kind of merging several tutorials together.
So far everything has been rather easy. What I wanted to do next is:
Display a static text in the middle of the screen, moving along with the camera.
in order to do so, I added the following the the ini file:
[PointsUI]
Graphic = PointsUIGraphic
;Position = (0, 0.25, 0.0)
Scale = 4.0
;Scale = 100
;Position = (-150.0, 100.0, 0)
;Position = (-65.0, -12.0, 0)
Position = (0.0, 0.0, 1.0)
ParentCamera = Camera
[PointsUIGraphic]
Text = PointsText
Color = (122, 122, 122)
Pivot = center
[PointsText] ;=========================
String = HalloWelt
Inside the Code I create this object:
orxObject_CreateFromConfig("PointsUI")
If I comment out the ParentCamera part, the text is displayed, but obviosly does not move along with the camera. this is the way it should be.
however, as soon as I uncomment the ParentCamera part I will not see the Text anymore.
what am I missing here?
https://forum.orx-project.org/uploads/legacy/fbfiles/files/Test.zip
Comments
This is something I've experienced myself, but haven't had time to actually look into. I think the combination of a ParentCamera and a Scale on an object is the problem. If you comment out Scale, you should see your text-object. I'm uncertain of how these two parameters should work together, but the problem happens even if the scale is 1.
I didn't have any luck without the scale.
In the scrolling tutorial the scale and the parentcamera are both set on the sky object. and it's working fine.
So, by default, when you use a ParentCamera, the property UseParentSpace is true. Which means, IF you specify a scale or a position, this one will be expressed in the parent's space.
So a scale of (1, 1, 1) means (1 x CameraWidth, 1 x CameraHeight, 1 x CameraDepth).
This is very handy for supporting multiple resolutions without having to change anything but it requires some knowledge.
What I usually do is that I design stuff around a given resolution, let's say 800 x 600.
Then I have my buttons and such. to place them, you simply place them in parent space: [-0.5, 0.5] as the Camera's origin in in the center of the viewport.
If I need to enforce some scale, ie. if you want your UI object to stretch when the aspect ratio changes, you simply have to divide it by the camera size. IE, a scale of (1, 1, 1) would become (1/800, 1/600, 1) (unfortunately orx can't do the math for you so you have to type (0.00125, 0.00167, 1)).
It's a bit annoying but you only have to do that once. When I want my UI object to be stretchable according to the aspect ratio, I simply add a property I call Scale in Camera or anywhere else where it doesn't mean anything, and then my UIObject is:
Now there's even a trick for supporting landscape/portrait change in real time for the UI, without having to change anything. This can be achieved by having 2 cameras, one for the game, one for the UI, and having inheritance between them. Well, I definitely should write a tutorial about UI, that would also include how to easily handle buttons for virtually any possible input.
That allows, for example, to plug virtual joysticks/buttons for a port of a game on mobile without having to change the game's code (except for the virtual joystick/button part, which is not intrusive).
If you're curious, I use such technique in ScrollEd, the embedded editor part of Scroll (that you can find with Mushroom Stew). I can add/remove buttons for any available actions in the editor just by adding some config lines without having to change a single line of code. Very scalable and handy, and the whole system only takes a couple of lines of code.
Hope this helps!
I haven't seen the editor of mushroom stew yet. but I'm gonna have a look at it's sources. those are probably a good information resource regarding UI elements.
I think I could just use the orxObject_SetScale inside the code, which scales it relatively. is there some way to do it inside the ini files?
btw, for some reason the newest SVN snapshot messes up most of my UI elements. Like all texts are extremely small. I have to figure out why. I think read something about scaling in the SVN commit log.
it also messes with the z-ordering of my objects, and I can't get an alpha fade-in effect to work.
I merged the sound recording branch with the current SVN version...maybe this messed up things.
update:
got the fade-in working. here the problem was sitting infront of my computer. I forgot that the values of the FX are by default relative and not absolute...made the same mistake now several times >.<
hope I learned it now^^
however the scaling is still a bit weird. how did you change it? when I set the scaling of my UI objects as (1/screenwidth, 1/screenheight, 1.0) then they will have the size of approx. 1 pixel.
Well now the scale is based on the parent but instead of using the resolution it uses a normalized value [0-1], which is easier to handle I hope.
Not sure what you mean by "is there some way to do it inside the ini files?", sorry.
Yes, sorry about that, I meant to post about it on the forum and just forgot when I submitted the code. ^^
So now instead of using the 1/rez scale, you can do it in camera space where 1 means the size of the camera frustum on both axes.
how would I for example scale some text?
let's say I have some text and I want it to spread half the screen, so it's scale attribute would be: but what about the scale on the y axis. how could I possibly set it in the ini file without making assumptions of the aspection ratio of the bounding box of the text?
Aspect ratio in 2D is tricky. As you might have noticed when the camera and the viewport don't share the same aspect ratio orx does automatic box lettering with black stripes.
If you want to be able to display full screen at different aspect ratio, the camera itself won't see the same quantity of world space, which is probably not a good thing for most 2D games.
In that case you can still scale the object in code according to the current aspect ratio depending on what was the one you had in mind when creating the assert.
The parent scale is more here if you want to keep the same aspect ratio but still scale the graphics so that it covers the same amount of screen between, for example, 800x600 and 1600x1200 which share the same aspect ratio.
Not sure if what I just wrote is clear. If it isn't just let me know!
how can I do something like this using the new normalized scale from 0 to 1?
- either have UseParentScale = false, then use regular scale and have a non-relative position
- don't add scale in config but add it in code as the UseParentScale is only used by the function orxObject_CreateFromConfig()
Would it be satisfactory for you?
http://orx-project.org/wiki/en/orx/config/settings_structure/orxobject
should I update it?
or is the wiki refering to the last release, which would be 1.2?
btw, when is 1.3 going to be officially released?
If it weren't for the personal problems I had over the few last weeks, the 1.3 would be out already. There's no work left for it, simply need to compile everything for all the platforms and I can't do it from here, unfortunately.
If someone feels like doing all the compiling for all the platforms, that'd be great, but it's a big chore, just so you're warned.