how to show the time on screen? [solved]

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Clodi
Posts: 175
Joined: November 18th, 2012, 7:47 pm

how to show the time on screen? [solved]

Post by Clodi » January 13th, 2013, 1:59 pm

Hello guys.
I know this is quite trivial but apparently not to me :)

I created a time object and with StartWatch() at the beginning of the program I measure time. Then I'd like to see the time running on screen. How to do this?
ANy help welcome :mrgreen:
Last edited by Clodi on January 26th, 2013, 7:56 pm, edited 1 time in total.

Clodi
Posts: 175
Joined: November 18th, 2012, 7:47 pm

Re: how to show the time on screen?

Post by Clodi » January 13th, 2013, 3:20 pm

this is my code, it runs fine but nothing appears on screen. ??

Code: Select all

	if ( FrameCounter == 0 )
	{
		FrameCounter = 1;
		timer.StartWatch();
	}
	else if ( FrameCounter == 10 )
	{
		FrameCounter = 0;
		timer.StopWatch();
		x = 10000 / timer.GetTimeMilli();
	}
	else
	{
		FrameCounter ++;
	}
	char Buffer[ 64 ];
	sprintf( Buffer,"%d frames per sec.",x );
	gfx.DrawString( Buffer,100,100,&fixedSys,D3DCOLOR_XRGB( 255,0,0 ) );

cameron
Posts: 794
Joined: June 26th, 2012, 5:38 pm
Location: USA

Re: how to show the time on screen?

Post by cameron » January 13th, 2013, 3:50 pm

I think I may have a soultion although I am having trouble in my game with time.

I would call stop watch first and gettimrmuli second then finally stop watch.
Computer too slow? Consider running a VM on your toaster.

Clodi
Posts: 175
Joined: November 18th, 2012, 7:47 pm

Re: how to show the time on screen?

Post by Clodi » January 13th, 2013, 5:10 pm

nope :(
The problem is with the DrawString function. Nothing shows up anyway.
Even if I commented everything out and I tried to print x (x = 0) , it would not print.

Clodi
Posts: 175
Joined: November 18th, 2012, 7:47 pm

Re: how to show the time on screen?

Post by Clodi » January 13th, 2013, 6:39 pm

it now works :)

Code: Select all

	//frame per sec.
	if ( FrameCounter == 0 ) { FrameCounter = 1; timer.StartWatch(); }
	else if ( FrameCounter == 10 ) { FrameCounter = 0; timer.StopWatch(); x = 10000 / timer.GetTimeMilli(); }
	else { FrameCounter ++; }
	char Buffer[ 64 ];
	sprintf( Buffer,"%f frames per sec.",x );
	gfx.DrawString( Buffer,0,0,&fixedSys,D3DCOLOR_XRGB( 255,0,0 ) );

	//sec. from start
	y = timer2.GetTimeMilli()/1000;
	char Buffer2[ 64 ];
	sprintf( Buffer2,"%f sec. u waste",y );
	gfx.DrawString( Buffer2,0,20,&fixedSys,D3DCOLOR_XRGB( 255,0,0 ) );

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: how to show the time on screen?

Post by LuX » January 14th, 2013, 3:34 pm

You should also use "sprintf_s" instead. You probably have your compiler complaining about warnings, something like "sprintf depreciated, use sprintf_s instead".
ʕ •ᴥ•ʔ

Post Reply