Saturday, January 3, 2015

Title Screen Navigation and Text

The navigation for sections of the title screen has evolved beautifully. Moving between sections is still the simple SPACE/ENTER/ESC keys but now responds better.

Previously, you'd have to wait for a section moving in to complete its tween in order to move to the next section. The user requesting to move to the next section before the current section finished moving in would get no response. My initial attempt to change this ended up with two sections on top of each other. This is because I tried to tween objects that were already in the middle of a tween. The next section moved in and the current section finished its move-in tween in the middle of the screen and then did not initiate the new tween request to move out. To solve this, I had to get very organized.

Working backwards, I needed to call the cancel() method for each VarTween object before the object being tweened could accept a new tween request. This meant storing each VarTween instance into an array in order to access it later. Since the method I use for a tween creates a VarTween object, all I needed to do was set its return type to VarTween and return the VarTween instance it creates.

The code to store the VarTween objects looks something like this:

for (each object:Object in objectList){
varTweenList.push(tween(object, "x", toCoord, duration));
}

That function tween(object, "x", toCoord, duration) returns the VarTween instance it creates right into the varTweenList.push().

The next thing was organizing all the objects that needed to be tweened into arrays. I gave each title screen section its own tweenList array that would store those objects. Doing this created a giant project in itself that forced me to revamp a major class, the TextPlus class.

I needed all objects that were going to be tweened to be entities but many of those objects were text objects. FlashPunk has a Text class so you can easily use text in your game. The Text class, however, is an Image object instead of an Entity. Sometime back, I had created TextPlus as an Entity that uses a Text object as it's graphic. Somewhere along the way of this game I made it so TextPlus's x and y values were always 0, 0 and changing where the text would display meant you had to access the Text object's x and y properties through TextPlus to change their values. Since I've used TextPlus so much, it took a lot of work to adjust every instance of it in the game.

In conclusion, now that everything is organized, the user is able to move through each section of the title screen without having to wait for each tween to finish. It now has a much more natural and smoother feel.

No comments:

Post a Comment