3

I've built an game in Libgdx which uses a single FitViewport passed-in to some Screens (Splash/Intro/Game/Menu/Pause etc.).

Each Screen has it's own Stage containing Groups of Actors - I've written a custom render loop to allow Screens to fade-in/out or slide around or render behind each-other - that's all great.

I now want a 'UI' screen which will rotate on smartphones to match their orientation (everything else in the game will NOT rotate).

I can make this work visually by using a TransformMatrix on the SpriteBatch but that doesn't affect the Stage's 'touch' detection (or debugdraw) and it seems there is no way to do this within the Stage (localtoparentcoords allows for rotation and scale but NOT transformation)

Bear in mind that it will not be 'square' (the FitViewport enforces 16x9 ratio) so it needs translation as well as rotation...

Note: I've tried to mess around with cameras but that's the wrong paradigm - cameras are a different view of the same thing - I want different things (transformation and rotated) drawn into the same view!

Note also: I've already started to create my own version of a Screen/Stage class to do this - I think it might be quicker than kicking the existing code into working properly but I'll be surprised if I'm the first person to want this?

  • Awesome for using libgdx and actually sounding like you know what you're doing. Just my opinion, but I wouldn't think someone playing a game that requires a specific orientation to even know a menu screen could be rotated, nevermind them actually rotating even if they knew they could. I personally wouldn't build a case just for this. Unfortunately, I don't know how you would do that though. – Kai Qing Oct 01 '14 at 23:44
  • I'll illustrate the idea - you have a top-down driving game or a shooter or a pool game where you'll want to rotate the device either for control or to line-up a shot or whatever. The game remains locked to the phones orientation but the UI (score, points, lives, multiplier or whatever) will rotate so that it remains readable - e.g. your score remains top-right, lives are bottom-left etc. etc. That's the sort of thing I'm trying to do (well - I'm actually doing it but not with Stage/Group/Actors atm) –  Oct 02 '14 at 01:30

1 Answers1

2

I think I've sort-of solved this by stepping-back a bit and looking at how the Stage/Actor system works.

The idea of rotating AND transforming an entire Stage is fraught with complexity - that I could do it at the SpriteBatch level was a distraction which led to a lot of wasted time - sadly.

It was only when I realised that as I was calculating the position of all my UI (Actor) elements relative to either the screen center or a corner, I may as well take the further step of rotating and transforming them at the same time! I also realised that Grouping them ,made this very simple (indeed I could have static and rotating elements simply by using 2 separate Groups!)

Rotating/Moving an Actor will, of course, adjust it's bounding box/touch-area as well - so I now have a proper Stage/Group/Actor model which rotates as the device is rotated - I could be just static information (scores) or even a dynamic menu or an overlay for a 'cue' in a pool game or whatever...

As Edison would have said - I didn't waste 2 days, I just spent 2 days coming up with a large number of ideas which I now know not to work!