From 0ac4fd09893e92ad82b642af675e33d6e1340968 Mon Sep 17 00:00:00 2001 From: Barry Kane Date: Wed, 22 Mar 2023 09:27:26 +0000 Subject: [PATCH] Make title fade in. --- Spacewar.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Spacewar.c b/Spacewar.c index 13344e0..be76778 100644 --- a/Spacewar.c +++ b/Spacewar.c @@ -125,7 +125,7 @@ int main(int argc, char ** argv) SDL_Rect textDestination = {0, 0, text->w, text->h}; SDL_Texture * textTexture = SDL_CreateTextureFromSurface(renderer, text); - int scrollX = 0; + int scrollX = 0, titleAlpha = 0, textAlpha = 0; // Render the title text: while(!inputSelected) { @@ -159,8 +159,27 @@ int main(int argc, char ** argv) { scrollX = 0; } + SDL_SetTextureAlphaMod(titleTexture, titleAlpha); SDL_RenderCopy(renderer, titleTexture, NULL, &titleRect); + if(titleAlpha < 254) + { + titleAlpha += 10; + } + if(titleAlpha >= 254) + { + titleAlpha = 254; + } + SDL_SetTextureAlphaMod(textTexture, textAlpha); SDL_RenderCopy(renderer, textTexture, NULL, &textDestination); + if(textAlpha < 254 && titleAlpha == 254) + { + textAlpha += 20; + } + if(textAlpha >= 254) + { + textAlpha = 254; + } + SDL_RenderPresent(renderer); SDL_PumpEvents();