The Mysterious Case of the Phantom Function
Aaaaaargh. This is doing my head in.
Perhaps unwisely, rather than implementing any more basic stuff just yet I decided to do something a bit more interesting: a function that will “drop” a word or phrase onto the screen one letter at a time, using SFML’s scaling function so that the letters appear to zoom in as if they were falling onto the surface of the screen from in front of it. (If that makes any sense.)
The function, which I’m calling zoomstring, will accept a nine-letter string as input so you can just call it as, e.g.
zoomstring (“GET READY”);
and the phrase “GET READY” will drop into the middle of the screen, letter by letter, and maybe wait a second or two before continuing with the main game loop.
So I worked out everything that zoomstring would have to do (transpose the contents of the string into an array of SFML’s sf::String objects, each holding one letter of the text. Calculate where each letter should be on the screen and how scaled up they need to be, and a loop to gradually scale them down and display them on screen at each iteration.)
Much to my surprise, compiling this produced no errors.
However, when I added a call to the function into my code (just before each new point is played for) a weird thing happened: nothing at all.
Again, my program didn’t give me any errors but the function call might as well not have been there. Everything proceeded exactly as before, with no sign of any text being dropped into the screen. Was it even really being called?
I added an extra line to the start of the function to spit a message out on the console every time zoomstring was called. Sure enough, next time I ran the game my console contained several lines of “calling zoomstring”. But that was the only clue that the function was there. No onscreen text, no errors.
Thoroughly bamboozled, I’m calling it a night.