So, the good news is, I was able to get done the things I was hoping to get done today. Unfortunately, it took me longer than expected. I'm still feeling like a newbie when it comes to Flash programming, and it definitely showed today.
For the high scores screen, I was able to provide a main menu option to get to it, and also went directly to it after the game over screen. I had, what I thought was, a clever boolean expression [...it's about to get technical]. I have a utility function to insert an item into an array based on the value of a named field it the item. The high scores have both a score field and a time field (so you can see how long it took you to get the score), but the items are still sorted by the score only. I provided a way to plug in an alternate function for determining whether or not two values are "in order," which led to the (not-so-clever) boolean expression inside an if statement:
if ((fn && fn(item[field], list[i][field]) < 0) || item[field] < list[i][field]))
The "intent" of this was to only call the user-supplied fn() function if it was present. Otherwise, just use a standard less-than operator. The problem is, if the fn() function is defined but returns something greater than or equal to zero, then the second part of that expression triggers, which is not what I want. In testing, I was seeing some strange orders for the scores (e.g. 0, 0, 90, 0, 0, 0). The highest number *should* be on top. Once I figured out that it was my utility function, it was an easy fix. I just changed the above line to this:
if ((fn && fn(item[field], list[i][field]) < 0) || (!fn && item[field] < list[i][field]))
The only change is the !fn && part. What that does is say, "don't use the less than operator unless the fn() function is specifically NOT defined." That took care of the ordering.
The next big challenge was for the pause menu. For all the screens up until this point, I was able to just destroy the old screen and replace it with the new one. Well, that would be rather irritating if pausing the game destroyed your progress. I recognized that there had to be a way to layer screens on top of each other so I could return the player to the old screen. I went through several variations on this. My initial thought was to change my curr_scene member into curr_scenes (instead of an object, it was now an array). After a bit of debugging, I realized this was unnecessary since Flash DisplayObjectContainer objects work like a stack already. So, I undid my previous changes and opted to just split my changeScene() function into two functions: pushScene() and popScene(). Those functions were now available in addition to changeScene(), which now just called popScene() and pushScene() in succession. A few minor changes were necessary to split the functions, but I essentially had exactly what I wanted.
I didn't really want the pause screen to just appear in place. So, I decided to add a "fade" transition to the screen manager. It turned out to be very simple. Rather than transitioning the x property of the screen, I transitioned the alpha property (0 --> 1 does a fade in, 1--> 0 does a fade out). So, I guess I got done even more than I expected today. :-)
I'm still having an issue with the resume button on the pause screen. It doesn't seem to want to handle clicks from the mouse, even though I set it up to do so just like the menu buttons. I'll probably figure it out tomorrow. It's past my bedtime... >_<
No comments:
Post a Comment