Nifty HUD

It’s a very n00b question: To create a simple FPS’s HUD with 4 boxes into the relatives screen’s corner are the following lines right to code with nifty? Or are there better ways? Maybe without so many layers?

Thanks

r.

[java]<nifty>

<screen id=“start” controller=“de.lessvoid.nifty.examples.helloworld.HelloWorldStartScreen”>

<layer id=“layer1” backgroundColor="#FFFFFF00" childLayout=“center”>

<panel id=“bottom right” height=“20%” width=“20%” align=“right” valign=“bottom” backgroundColor="#00000040">

</panel>

</layer>



<layer id=“layer2” backgroundColor="#FFFFFF00" childLayout=“center”>

<panel id=“top right” height=“20%” width=“20%” align=“right” valign=“top” backgroundColor="#00000040">

</panel>

</layer>



<layer id=“layer3” backgroundColor="#FFFFFF00" childLayout=“center”>

<panel id=“bottom left” height=“20%” width=“20%” align=“left” valign=“bottom” backgroundColor="#00000040">

</panel>

</layer>



<layer id=“layer4” backgroundColor="#FFFFFF00" childLayout=“center”>

<panel id=“top left” height=“20%” width=“20%” align=“left” valign=“top” backgroundColor="#00000040">

</panel>

</layer>

</screen>

</nifty>[/java]

Layer are used to specify which part of the gui should be in front.



In your case, it doesn’t seem you need them.

It may be best to use something like that instead :



[xml]

|nifty|

|screen id=“start” controller=“de.lessvoid.nifty.examples.helloworld.HelloWorldStartScreen”/|

|layer id=“mainLayer” backgroundColor="#FFFFFF00" childLayout=“center”|



|panel height=“100%” width=“100%” align=“center” valign=“center” childLayout=“vertical” |



|!-- Top --|

|panel height=“20%” childLayout=“horizontal” |

|panel id=“top left” height=“100%” width=“20%” align=“right” valign=“bottom” backgroundColor="#00000040"/|

|panel width=“60%” /|

|panel id=“top right” height=“100%” width=“20%” align=“right” valign=“bottom” backgroundColor="#00000040"/|

|/panel|



|panel height=“60%” /|



|!-- Bottom --|

|panel height=“20%” childLayout=“horizontal” |

|panel id=“bottom left” height=“100%” width=“20%” align=“right” valign=“bottom” backgroundColor="#00000040"/|

|panel width=“60%” /|

|panel id=“bottom right” height=“100%” width=“20%” align=“right” valign=“bottom” backgroundColor="#00000040"/|

|/panel|



|/panel|

|/layer|

|/screen|

|/nifty|

[/xml]

2 Likes

does that actually work? :smiley: great use of the center childLayout if it does :wink:



you could use something like this, I think:



[xml]<panel childLayout=“vertical” …

<panel childLayout=“horizontal” …

<panel id=“topLeft” …

<panel id=“topSpacer” …

<panel id=“topRight” …

</panel>

<panel id=“vertical-spacer”…

<panel childLayout=“horizontal” …

<panel id=“bottomLeft” …

<panel id=“bottomSpacer” …

<panel id=“bottomRight” …

</panel>

</panel>[/xml]



with some additional attributes for width/height and so on.



That is the first that came to my mind. There are different solutions possible I’m sure.

2 Likes

lol congratz didialchichi! you’re faster! :smiley:

Still, points for effort! :stuck_out_tongue:

Thank you both[+1 +1]! I’ll try each your answer and I’ll which suits better my poor knowledge of nifty…

r.