drawing sprites

Started by
87 comments, last by Tom Sloper 6 years, 9 months ago

I did some research on auto but I am still confused on how to output the elapsed variable to the screen. I am trying to cout the elapsed variable.


	chrono::high_resolution_clock::time_point previous = chrono::high_resolution_clock::now();
	auto timeStampPrevious = previous;
	auto timeStampNow = chrono::high_resolution_clock::now();
	auto elapsed = timeStampPrevious - timeStampNow;
	cout << elapsed << endl;
	

Advertisement

You need to be more clear with the problem you're facing. What does the code you posted do? How does the output differ from what you expect?

@phil67rpg

Have you ever considered using a library such as Allegro, SDL or SFML? They take care of how to do most of the things you ask about, which allows you to focus on what you want to do instead. 

here is my error

 1 IntelliSense: no operator "<<" matches these operands
            operand types are: std::ostream << std::chrono::duration<std::chrono::system_clock::rep, std::chrono::system_clock::period> c:\Users\phil6_000\Desktop\cpp24a\cpp24a\cpp24a.cpp 14 7 cpp24a
I am getting variable type conflict, the << operator does not work with chrono types.


cout << elapsed

Would assume its that bit of code since its saying there << operator doesnt work with chrono types?

There are no overloaded << operators for duration. When you encounter a problem using some code the way you expect, one of the first things you should do is look up the documentation for that code. You have been linked to cppreference.com several times in this thread. It's a great source of documentation for the C++ standard library and part of the language itself, and you should start using it rather than expecting the members of this forum to act as Google proxies for you.

If you want to print a representation of a duration variable, a brief read-through of that linked documentation would suggest that the count() function is probably what you want to call to retrieve the number of ticks of the duration's period (that is, the number of seconds if the duration is measuring seconds, the number of milliseconds if the duration is measuring milliseconds, et cetera).

yes you are correct

I have looked at the cppreference code I just thought there would be quick fix, I guess I was wrong.

I also want to say that I am learning a lot about c++, thanks jpetrie

thanks jpetrie, I stubbed out some code, I figured out how to print out the microseconds it takes to print out some text. I am posting my code so you know that I am really working on this problem. once again thanks for all the help.


	auto timeStampPrevious = chrono::high_resolution_clock::now(); 
	cout << "Hello World\n";
	auto timeStampNow = chrono::high_resolution_clock::now();
	auto elapsed = timeStampNow - timeStampPrevious;
	cout << chrono::duration_cast<chrono::microseconds>(elapsed).count() << endl;
	

here is my stubbed out code, it works on its own, I have not put it into my game, can you look at it jpetrie and let me know if it is correct for what I am trying to accomplish.


	auto timeStampPrevious = chrono::high_resolution_clock::now(); 
	cout << "Draw Sprite One\n";
	auto timeStampNow = chrono::high_resolution_clock::now();
	auto elapsed = timeStampPrevious - timeStampNow;
	if (chrono::duration_cast<chrono::microseconds>(elapsed).count() < 0)
	{
	cout << "Draw Sprite Two" << endl;
	}
	

This topic is closed to new replies.

Advertisement