Our Latest HaxeFlixel Contribution: Zelda Style Screen Transitions
The title is probably a little deceptive. The truth is that HaxeFlixel already has such a camera transition. However, it didn’t function 100% in the way it needed to. You can follow this problem in this HaxeFlixel forum post.
The problem was simple. I was using grid based movement for my character. I was following that character with the camera. When that character moved off the current screen to the north or west, everything was fine. You took one step off screen and the camera switched. However, when you tried moving east or south off the screen, you had to take two full steps off the screen.
This presented a problem as the character might have interactions waiting for them on the next screen that could be impacted by taking a “blind” step into it.
Consider the original Zelda game. In some rooms in the dungeons, there are spiked blocks that move quickly to damage you when you cross their path. These blocks are often positioned so that the path is the very next row of blocks after a doorway. In Zelda, you always start a room standing in the doorway. So if the camera in Zelda functioned the way it did in Flixel, you would have had to move directly into the path of the spikes to switch the screen.
The fix was really easy. The camera was checking to see if you were on the next screen, but was using a greater than sign (>) to do it. This meant that the player character had to be 1 pixel greater than the screen width to trigger the change. In many games, this wouldn’t be an issue. But with the introduction of grid based movement, where the player moves a set number of pixels with each directional press, this is a huge problem. If the squares in the grid are 16 pixels wide, that means you have to move a full 16 pixels into the next room to trigger the camera shift.
So the fix for this was to simply change the greater than sign to a greater than or equal to sign (>=). Once again, the change is nearly imperceptible if you are not using grid based movement. But for those of us that are, it makes a world of difference.
So this makes my second HaxeFlixel contribution and my first to the actual HaxeFlixel API. If I keep this up, I might just become a HaxeFlixel contributing junkie.