Advertisement

drawing sprites

Started by June 22, 2017 04:18 AM
87 comments, last by Tom Sloper 7 years, 4 months ago

You should try it yourself. This forum is not your compiler.

 

If it works - great! Move on to the next step you want to solve.

If it doesn't work - try looking at the code and understanding why it does what it does, and what needs to be different in order for it to work as you want it to. If you are still stuck after spending time on trying to solve the problem yourself, post with the current code + description of expected behavior + description of current/actual behavior.

 

Note that this methodology applies to more than just this specific issue.

Hello to all my stalkers.

this code works a stubbed out code.

josh could you look at my code and let me know if it is appropriate to solve my problem.

Advertisement

Does it run and produce the results that you were intending when you sat down to write it?

well josh I am working on what you posted earlier, I am trying to code a counter algorithm for my game.

well josh can you look at this code and let me know if it works as a counter as you instructed me to do in an earlier post. I have been working on this problem for a long time.


	auto timeStampNow = chrono::high_resolution_clock::now();
	cout << "Draw Sprite One\n";
	auto timeStampPrevious = chrono::high_resolution_clock::now();
	auto elapsed = timeStampNow - timeStampPrevious;
	auto timeUntilSecondSprite = chrono::high_resolution_clock::now();
	timeUntilSecondSprite += elapsed;
	if (timeUntilSecondSprite <= timeStampPrevious)
	{
	cout << "Draw Sprite Two" << endl;
	}
	timeStampPrevious = timeStampNow;
	

Just now, phil67rpg said:

well josh can you look at this code and let me know if it works as a counter as you instructed me to do in an earlier post. I have been working on this problem for a long time.

 

On 6/27/2017 at 0:32 AM, jpetrie said:

Does it run and produce the results that you were intending when you sat down to write it?

 

Hello to all my stalkers.

Advertisement

well I put my code into my game, it still does not put a wait period in my drawScene() function. here is the code I am working on


	void drawScene() {
	glClear(GL_COLOR_BUFFER_BIT);
	auto timeStampNow = chrono::high_resolution_clock::now();
	drawScene_bug();
	auto timeStampPrevious = chrono::high_resolution_clock::now();
	auto elapsed = timeStampNow - timeStampPrevious;
	auto timeUntilSecondSprite = chrono::high_resolution_clock::now();
	timeUntilSecondSprite += elapsed;
	if (timeUntilSecondSprite <= timeStampPrevious)
	{
	drawScene_bug_two();
	}
	// drawScene_bug();
	// eraseScene_bug();
	// drawScene_bug_two();
	// eraseScene_bug_two();
	upper_row_one();
	upper_row_two();
	upper_row_three();
	upper_row_four();
	upper_row_five();
	upper_row_six();
	upper_row_seven();
	upper_row_eight();
	upper_row_nine();
	drawScene_ship();
	drawScene_bullet();
	timeStampPrevious = timeStampNow;
	glutSwapBuffers();
	}
	

In one of Josh's earlier posts he said where the timeStampPrevious variable should be stored. It needs to be a member variable of a class (which also contains the drawScene function), or it needs to be a global variable or something similar. It should also be initialized once, not every time the function is run. Globals are not the best suggestion (they rarely are), but it might be easier to start with a global and make things work.

Similarly for the timeUntilSecondSprite variable. It is currently created, initialized every time the function is called, and is destroyed once the function exits.

If you want to have info persist across multiple calls to the same function, you can't use just local variables like you are currently doing.

 

In general, there's a lot of strange stuff in your code. Read through your code line by line and try to understand what each line is supposed to do.

 

Additionally, all the "upper_row_xxx" functions also screams that you should look into loops as well, but that's a problem for another time...

Hello to all my stalkers.

On 6/22/2017 at 10:04 AM, phil67rpg said:

sorry but the question is how do I draw a sprite and then wait for  a period of time and then draw another sprite over it.

I'm wondering, why are you trying to do this? Are you trying to do some basic animations?

8 minutes ago, kseh said:

I'm wondering, why are you trying to do this? Are you trying to do some basic animations?

I am working on a space invaders game.

This topic is closed to new replies.

Advertisement