Tuesday, October 13, 2015

Dev Update # 12: Pausing Audio, UI Elements Correctly Scaling


I've decided to add  more pictures and more technical information into my dev updates.  I've also decided to do a write up on my progress/lack thereof immediately after I've made the progress/lack thereof.  Instead of making a lot of dev updates, I will add to them until I feel like I have enough material before posting.

10/12/2015 I found a way to pause and play the music in the game, using "AudioListener.pause" instead of turning on and off the SoundManager object. One benefit to this, is that the music will begin playing where it left off instead of restarting every time. Also, Unity can't find an object when it's not active, and this is why the sound breaks using my current "reset game" code. One downside the AudioListener pauses all of the audio including the music and sound effects. Apparently can "set the ignoreListenerPause property" to true for sound effects, to prevent this, but I'm not entirely sure how to do this yet. A snippet of my code is below. This is the body of a function I have that runs when the music button is pressed, or the "M" button is pressed.
if (AudioListener.pause == false)
        { AudioListener.pause = true; }
        else
        { AudioListener.pause = false; }

10/13/2015  I readjusted some of the UI elements that weren't scaling with everything else, so they would scale correctly.  I changed the anchors to top horizontal stretch(not sure if the top part is important, but I know that adding vertical stretch will generally break everything. see Image 1).  Anchors and pivots with the new UI system are a bit confusing.  I think maybe I'm starting to understand them a little.

I was having trouble getting the left and right panels to scale with the game board in the middle.  I created a panel that mimics the game board, to make it easier.  The game board is always square, 1x1, so as the window scales the game board gets bigger or smaller in the middle.  Initially, the left and right panels stayed the same width, because there was no width scaling which would create large black areas on the left and right of the game board(see image 2), or the panels would overlap the game board.  Every time I changed the anchors, the panels would scale, but they would scale incorrectly.

To fix this, after a LOT of trial and error, I set the inside anchors to the middle of the screen.  Don't ask me why this works or how I thought of trying it.  I have a very vague idea, but I couldn't explain it.
Success!!! UI Elements scale correctly.

Image 1: vertical scaling breaking UI elements, before I fixed it

Image 2: Gaps between Game Board and Panels

No comments:

Post a Comment