Orx - Portable Game Engine
Welcome, Guest
Please Login or Register.    Lost Password?
Displaying an UI text
(1 viewing) 1 Guest
Go to bottom
TOPIC: Displaying an UI text
#1215
tdomhan
Expert Boarder
Posts: 132
graphgraph
User Offline Click here to see the profile of this user
Location: Tampere, Finland
Displaying an UI text 6 Years, 6 Months ago Karma: 2
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:
Code:

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?
File Attachment:
File Name: Test.zip
File Size: 1223592
 
Logged Logged
  The administrator has disabled public write access.
#1219
ekerik
Senior Boarder
Posts: 56
graphgraph
User Offline Click here to see the profile of this user
wombamomba@hotmail.com Location: Sweden
Re:Displaying an UI text 6 Years, 6 Months ago Karma: 1
Hello there,
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.
 
Logged Logged
  The administrator has disabled public write access.
#1220
tdomhan
Expert Boarder
Posts: 132
graphgraph
User Offline Click here to see the profile of this user
Location: Tampere, Finland
Re:Displaying an UI text 6 Years, 6 Months ago Karma: 2
ok thanks for the tip.
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.
 
Logged Logged
  The administrator has disabled public write access.
#1223
iarwain
Administrator
Posts: 3107
graph
User Offline Click here to see the profile of this user
Gender: Male Orx - Portable Game Engine Location: Montreal
Re:Displaying an UI text 6 Years, 6 Months ago Karma: 71
Yes, I should probably write a tutorial on this one!

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:
Code:


[UIObject]
Position = (0.25, 0.25, 0.0001) <= very close to the camera, whereas a Z = 1 would send it to the background
Scale = @Camera



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!
 
Logged Logged
 
Want to follow orx's development? Go subscribe to the orx-dev group at: https://groups.google.com/forum/?fromgroups#!forum/orx-dev
  The administrator has disabled public write access.
#1224
iarwain
Administrator
Posts: 3107
graph
User Offline Click here to see the profile of this user
Gender: Male Orx - Portable Game Engine Location: Montreal
Re:Displaying an UI text 6 Years, 6 Months ago Karma: 71
As for the sky, you can see how the scale works: the sprite is 2 pixels wide, and the scale is 0.5, 2 * 0.5 * CameraWidth = the whole screen. And it's resolution independent.
 
Logged Logged
 
Want to follow orx's development? Go subscribe to the orx-dev group at: https://groups.google.com/forum/?fromgroups#!forum/orx-dev
  The administrator has disabled public write access.
#1230
tdomhan
Expert Boarder
Posts: 132
graphgraph
User Offline Click here to see the profile of this user
Location: Tampere, Finland
Re:Displaying an UI text 6 Years, 6 Months ago Karma: 2
ok thanks for explaining.
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.
 
Logged Logged
  The administrator has disabled public write access.
#1367
tdomhan
Expert Boarder
Posts: 132
graphgraph
User Offline Click here to see the profile of this user
Location: Tampere, Finland
Re:Displaying an UI text 6 Years, 4 Months ago Karma: 2
I think it's good to inherit the scale from a single object, like:
Code:

Scale = @Camera 

then it's easy to change it according to the aspect ratio. however then all object's will have the same scale. but I would for example like to have text objects that have different scales, e.g. heading vs normal text.
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.
 
Logged Logged
 
Last Edit: 2010/12/02 12:34 By tdomhan.
  The administrator has disabled public write access.
#1369
iarwain
Administrator
Posts: 3107
graph
User Offline Click here to see the profile of this user
Gender: Male Orx - Portable Game Engine Location: Montreal
Re:Displaying an UI text 6 Years, 4 Months ago Karma: 71
tdomhan wrote:
I think it's good to inherit the scale from a single object, like:
Code:

Scale = @Camera 

then it's easy to change it according to the aspect ratio. however then all object's will have the same scale. but I would for example like to have text objects that have different scales, e.g. heading vs normal text.
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?


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. :/

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.

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.
 
Logged Logged
 
Want to follow orx's development? Go subscribe to the orx-dev group at: https://groups.google.com/forum/?fromgroups#!forum/orx-dev
  The administrator has disabled public write access.
#1371
tdomhan
Expert Boarder
Posts: 132
graphgraph
User Offline Click here to see the profile of this user
Location: Tampere, Finland
Re:Displaying an UI text 6 Years, 4 Months ago Karma: 2
ok good to know. this solves the other problem I was having, which I was not able to state understandably^^
Not sure what you mean by "is there some way to do it inside the ini files?", sorry. :/
 
Logged Logged
 
Last Edit: 2010/12/02 21:30 By tdomhan.
  The administrator has disabled public write access.
#1373
tdomhan
Expert Boarder
Posts: 132
graphgraph
User Offline Click here to see the profile of this user
Location: Tampere, Finland
Re:Displaying an UI text 6 Years, 4 Months ago Karma: 2
ok it doesn't.
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:
Code:

Scale = (0.5,???,1.0)

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?
 
Logged Logged
  The administrator has disabled public write access.
#1375
iarwain
Administrator
Posts: 3107
graph
User Offline Click here to see the profile of this user
Gender: Male Orx - Portable Game Engine Location: Montreal
Re:Displaying an UI text 6 Years, 4 Months ago Karma: 71
Well, short answer: you can't do it in config.

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! =)
 
Logged Logged
 
Want to follow orx's development? Go subscribe to the orx-dev group at: https://groups.google.com/forum/?fromgroups#!forum/orx-dev
  The administrator has disabled public write access.
#1379
tdomhan
Expert Boarder
Posts: 132
graphgraph
User Offline Click here to see the profile of this user
Location: Tampere, Finland
Re:Displaying an UI text 6 Years, 4 Months ago Karma: 2
Ok so far I created all my UI objects(texts and other objects) like this:
Code:

[UIObject]
Position      = (0, -0.38, 0.0001)
Scale = (0.00078125, 0.0010416666666667, 1)
;Scale = (1/width*x-scale, 1/height*y-scale, 1)
ParentCamera = Camera
UseParentSpace  = true



how can I do something like this using the new normalized scale from 0 to 1?
 
Logged Logged
  The administrator has disabled public write access.
#1381
iarwain
Administrator
Posts: 3107
graph
User Offline Click here to see the profile of this user
Gender: Male Orx - Portable Game Engine Location: Montreal
Re:Displaying an UI text 6 Years, 4 Months ago Karma: 71
The formula becomes:
Code:


Scale = (1/width*x-scale*x-size, 1/height*y-scale*y-size, 1)

 
Logged Logged
 
Want to follow orx's development? Go subscribe to the orx-dev group at: https://groups.google.com/forum/?fromgroups#!forum/orx-dev
  The administrator has disabled public write access.
#1382
iarwain
Administrator
Posts: 3107
graph
User Offline Click here to see the profile of this user
Gender: Male Orx - Portable Game Engine Location: Montreal
Re:Displaying an UI text 6 Years, 4 Months ago Karma: 71
Another option would be to:
- 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()
 
Logged Logged
 
Want to follow orx's development? Go subscribe to the orx-dev group at: https://groups.google.com/forum/?fromgroups#!forum/orx-dev
  The administrator has disabled public write access.
#1383
iarwain
Administrator
Posts: 3107
graph
User Offline Click here to see the profile of this user
Gender: Male Orx - Portable Game Engine Location: Montreal
Re:Displaying an UI text 6 Years, 4 Months ago Karma: 71
I guess I could update the meaning of UseParentScale, keeping false/true for compatibility and add "both", "position" and "scale" as values meaning you could have parent scaling for only position or scale if you choose so.
Would it be satisfactory for you?
 
Logged Logged
 
Last Edit: 2010/12/03 08:11 By iarwain.
 
Want to follow orx's development? Go subscribe to the orx-dev group at: https://groups.google.com/forum/?fromgroups#!forum/orx-dev
  The administrator has disabled public write access.
#1384
tdomhan
Expert Boarder
Posts: 132
graphgraph
User Offline Click here to see the profile of this user
Location: Tampere, Finland
Re:Displaying an UI text 6 Years, 4 Months ago Karma: 2
yeah, I think this would be great. thanks for your help!
 
Logged Logged
  The administrator has disabled public write access.
#1385
iarwain
Administrator
Posts: 3107
graph
User Offline Click here to see the profile of this user
Gender: Male Orx - Portable Game Engine Location: Montreal
Re:Displaying an UI text 6 Years, 4 Months ago Karma: 71
No problem. I'll do it tomorrow though, getting tired for tonight. =)
 
Logged Logged
 
Want to follow orx's development? Go subscribe to the orx-dev group at: https://groups.google.com/forum/?fromgroups#!forum/orx-dev
  The administrator has disabled public write access.
#1835
tdomhan
Expert Boarder
Posts: 132
graphgraph
User Offline Click here to see the profile of this user
Location: Tampere, Finland
Re:Displaying an UI text 6 Years ago Karma: 2
I just noticed that the wiki doesn't reflact this change:
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?
 
Logged Logged
  The administrator has disabled public write access.
#1839
iarwain
Administrator
Posts: 3107
graph
User Offline Click here to see the profile of this user
Gender: Male Orx - Portable Game Engine Location: Montreal
Re:Displaying an UI text 6 Years ago Karma: 71
Well, I try to keep the tutorial synced with the latest release and not with the svn.

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.
 
Logged Logged
 
Want to follow orx's development? Go subscribe to the orx-dev group at: https://groups.google.com/forum/?fromgroups#!forum/orx-dev
  The administrator has disabled public write access.
Go to top