Jump to content

Layouts


royibernthal
 Share

Recommended Posts

I couldn't find any nice way to do it to be honest. Any 3rd party libs weren't being maintained and I couldn't be bothered coding the solution myself - instead I just have each "gui" in its own function and if the viewport resizing I destroy the GUI and redraw it... Still I'm not happy with that as the solution but I had to crack on with the game itself.

So I recorded some resizing so you can see, it has some unpleasant side effects on the actual resize but after that its fairly sound. The code isn't too much of a nightmare to manage but I think my organised codebase helps with that.

 

Link to comment
Share on other sites

Looks like you did a good job there.

What do you mean by destroy the GUI then redraw it? Is simply re-adjusting anchors/pivots/positions not enough? Doesn't the redraw happen automatically?

Are anchors and pivots relative to their parent the way positions are?

Link to comment
Share on other sites

5 hours ago, royibernthal said:

Looks like you did a good job there.

What do you mean by destroy the GUI then redraw it? Is simply re-adjusting anchors/pivots/positions not enough? Doesn't the redraw happen automatically?

Are anchors and pivots relative to their parent the way positions are?

I anchor/pivot the positions manually based on view port width and height, no built in pixi help (although I can imagine some way to do it, but I wanted full control).

Consider I have a challenge menu. I run game.ui.challengeMenu() to create it, if I ever need to redraw it and let its position change, I just destroy it with game.ui.closeChallengeMenu() then recreate it again with game.ui.challengeMenu(); Since I use game.ui._VIEWPORT_RIGHT [+] (A var which sets itself to viewport width on resize), then all the sprites will be in their new positions when the menu is recreated. I could of course write a "resize/reposition" function for every UI, but that feels like more dev-time, while this isn't the most elegant or efficient it works, you write it once, and then it's done.

 

Link to comment
Share on other sites

6 minutes ago, royibernthal said:

I see, but technically destroying it is not a requirement for it to work. Another option should be to iterate over the menu's items and just modify their positions, correct?

I just saw your edit, it answered my question. Thanks :)

Yep, you're completely right. I did wonder like, if I had one overall array/object containing things I might want to reposition then I could reposition them all. But after all the thinking, existing UI's and the pain I'd have trying to manage for example 5 GUI's each within their own "container" kinda thing, then having to update all their position... Even now I struggle to really think of a good solution without creating a real good layout library, at that point im not making my game anymore tho so I have to crack on hahaha.

Glad the info helps.

Link to comment
Share on other sites

20 hours ago, royibernthal said:

How about separating the creation and positioning logic?

Call the positioning on creation and on resize, that way you don't have to deallocate and reallocate memory on each resize.

Yup its possible, it adds more coding though for the sake of saving memory when the games resized (which should be rare). I picked saving development time!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...