How to make font flash and change colour

I am trying to get my font to flash and Change colour on my splash screen I tried getting it to change by using delta time at 2 second increment but it Only updates once then switches into My main menu and font never seems to change colour I gone break point crazy on this but I cant seem to identify were the problem lies Also I can post up font class and Delta time class's if needed Thanks for your time

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

if( (m_fFrameWaiting += pDT->GetDeltaTime()) <= 2)
	{				
		pFont->SetFont_Width_Height( 40, 30 );	
		pFont->SetFont_Colour( 0, 0, 0 );		
		pFont->SetFont_Opacity( 200 );			
		pFont->SetFont_Position( 128, 50 );		
		pFont->PrintFont( "Forest Of Serenity");
	}
	else if ( (m_fFrameWaiting += pDT->GetDeltaTime()) >= 4)
	{				
		pFont->SetFont_Width_Height( 40, 30 );	
		pFont->SetFont_Colour( 50, 50,  50);		
		pFont->SetFont_Opacity( 200 );			
		pFont->SetFont_Position( 128, 50 );		
		pFont->PrintFont( "Forest Of Serenity");
	}

	else if ( (m_fFrameWaiting += pDT->GetDeltaTime()) >= 6)
	{				
		pFont->SetFont_Width_Height( 40, 30 );	
		pFont->SetFont_Colour( 100, 100,  100);		
		pFont->SetFont_Opacity( 200 );			
		pFont->SetFont_Position( 128, 50 );		
		pFont->PrintFont( "Forest Of Serenity");
	}


What GUI library are you working with?

I think the problem is elsewhere in you code. If I understand you correctly, the code fragment you posted above is called just once. So it's the code which is calling this code which is of more interest.

But I note you are incrementing the time on every comparison. Did you mean to do that, or did you just want to increment it once and then work out which color was needed? (And the time slot 2-4 doesn't appear to be covered?

Andy

PS Your code looks like it could be factored so that only the color is set conditionally. (I'm assuming you wanted the member variable stepped on each call?)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
	m_fFrameWaiting += pDT->GetDeltaTime();

	pFont->SetFont_Width_Height( 40, 30 );
	pFont->SetFont_Opacity( 200 );
	pFont->SetFont_Position( 128, 50 );

	if( m_fFrameWaiting <= 2)
		pFont->SetFont_Colour( 0, 0,  0);	
	else if ( m_fFrameWaiting >= 4)
		pFont->SetFont_Colour( 50, 50,  50);		
	else if ( m_fFrameWaiting >= 6)
		pFont->SetFont_Colour( 100, 100,  100);		

	pFont->PrintFont( "Forest Of Serenity");

Last edited on
The gui I using is "sdl_opengl.h"

Its meant to flash on every 2 seconds with a different colour and every other second not be visible

Umm the entire .cpp file for that is below

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//\====================================================================================
//\ Author: Declan.Corcoran
//\ About : SplashScreenState.cpp - 
//\
//\ Creates the SplashScreenState source file. This cpp defines the Splash Screen that 
//\ is to be used just before the game takes you into the menu state.
//\
//\ This cpp file defines the waiting period until the transition occurs
//\====================================================================================
#include "DeltaTime.h"
#include "Scene_SplashScreen.h"
#include "SceneManager.h"
#include "Sprite.h"
#include "InputHandler.h"
#include "Texture.h"
#include "ScreenResolution.h"
#include "Weather.h"
#include "Font.h"

#include <string>
#include <vector>

//#include "AnimatedSprite.h"

// DECLAN FOR FUCK SAKE, DON'T USE ANY MAGIC NUMBERS; I GOT IT WORKING FOR YOU, BUT I'M NOT GONNA LEAVE YOU WITH NO WORK TO DO ;)
Scene_SplashScreen::Scene_SplashScreen(SceneManager* p_Scene)
{
	m_pSceneManager = p_Scene;
	m_pSprite = new Sprite( "SplashScreen.JPG", "BackGround" );
	m_pWeather = new Weather();
}

Scene_SplashScreen::~Scene_SplashScreen()
{
	delete m_pSprite;
	delete m_pWeather;
}

void Scene_SplashScreen::OnLoad()
{
	m_pSprite->OnLoad();

	m_pWeather->OnLoad();
	m_pWeather->StartWeather( "Rain", 6, false );

	m_v2BackGroundPos = Vector2(0,0);
	m_v2BackGroundSize  = Vector2( 4096, 768.f);

	m_pSprite->SetSize( m_v2BackGroundSize.X, m_v2BackGroundSize.Y );

	m_fFrameWaiting	= 0;
	m_fWaitTimeAmount = 10.01f; // Seconds

	m_pInputHandler = InputHandler::GetInstance();
}

void Scene_SplashScreen::OnUnload()
{
	m_pSprite->OnUnload();
	m_pWeather->OnUnload();
}

void Scene_SplashScreen::Update()
{
	ScreenScroll(); 
	DeltaTime* pDT = DeltaTime::GetInstance();
	m_pWeather->Update(Vector2(0,0));

	m_fFrameWaiting += pDT->GetDeltaTime();

	if( m_fFrameWaiting >= m_fWaitTimeAmount )
	{
		m_pSceneManager->ChangeState( SceneManager::eMENU_STATE );
	}
	if(m_pInputHandler->GetKeyState( SDLK_SPACE ) || m_pInputHandler->GetKeyState( SDLK_RETURN))
	{
		m_pSceneManager->ChangeState( SceneManager::eMENU_STATE );
	}
}

void Scene_SplashScreen::Draw()
{
	m_pSprite->Draw( m_v2BackGroundPos.X, m_v2BackGroundPos.Y, m_v2BackGroundSize.X, m_v2BackGroundSize.Y, false );
	m_pWeather->Draw();

	if( (m_v2BackGroundPos.X + m_v2BackGroundSize.X) < ScreenResolution::GetInstance()->GetScreenWidth() )
	{
		m_pSprite->Draw( (m_v2BackGroundPos.X + m_v2BackGroundSize.X), m_v2BackGroundPos.Y, m_v2BackGroundSize.X, m_v2BackGroundSize.Y, false );
	}

	//////////////////////////////////////
	//		Title Screen				//
	//////////////////////////////////////
	Font* pFont = Font::GetInstance();		
	DeltaTime* pDT = DeltaTime::GetInstance();
	if( (m_fFrameWaiting += pDT->GetDeltaTime()) < 2)
	{				
		pFont->SetFont_Width_Height( 40, 30 );	
		pFont->SetFont_Colour( 0, 0, 0 );		
		pFont->SetFont_Opacity( 200 );			
		pFont->SetFont_Position( 128, 50 );		
		pFont->PrintFont( "Forest Of Serenity");
	}
	else if ( (m_fFrameWaiting += pDT->GetDeltaTime()) > 4)
	{				
		pFont->SetFont_Width_Height( 40, 30 );	
		pFont->SetFont_Colour( 50, 50,  50);		
		pFont->SetFont_Opacity( 200 );			
		pFont->SetFont_Position( 128, 50 );		
		pFont->PrintFont( "Forest Of Serenity");
	}
}

void Scene_SplashScreen::ScreenScroll()
{
	m_v2BackGroundPos.X -= 300 * DeltaTime::GetInstance()->GetDeltaTime();

}



it only gets called in from draw while the splash screen is going, splash screen only lasts 10 seconds then switches by default to main menu

if there is anything you would like me to link in perticular just tell me
Last edited on
but it Only updates once

If Scene_SplashScreen::Draw() is only ever being called once, it seems you need something to trigger the redraw.

Unfortunately I don't know SDL, so I don't know what to suggest next.

Any SDL types about???

Andy
Try adding a message box or some breakpoint in your Scene:SplashScreen::Draw function's beginning.

I'd create a FlashingText Class.
Then you should hold a variable that holds the color you want and the time that the flashing action should be triggered.
Each frame you change this color from the class interface, using linear interpolation if you prefer, remember to use the delta time for better linear calculations that don't change from pc to pc.
Whithin the class's Draw function (you will have to make one i guess?) you do the flashing computations and eventually draw the text.
Topic archived. No new replies allowed.