Advertisement

drawing sprites

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

well I have put my code in a separate function from the drawScene() function. I am going to work on this new function.

here is a very simple counter algorithm, am I on the right track with this code?


	int main()
	{
	int count = 10;
	while (count >= 6)
	{
	cout << "draw_bug" << endl;
	count--;
	if (count <= 5)
	{
	for (int i = 0; i <= 4; i++)
	{
	cout << "draw_bug_two" << endl;
	}
	}
	}
	system("pause");
	return 0;
	}
	

Advertisement

Does it do what you want? We cannot tell you if you are "on track" if you don't explain what you're trying to do. I strongly suggest that you take some time to gather your own thoughts about your goals, because you don't seem to have a coherent plan in mind. You just seem to be flailing around randomly and incoherently; certainly what you're communicating to us is inconsistent and difficult to follow. We cannot read your mind, so you need to put together a more complete description of what you are trying to accomplish.

I highly recommend you read this.

well I cant get the num variable to work with the chrono type. here is my code, the num variable gives me an error, "expected a ';'" error.


	auto timeStampPrevious = chrono::high_resolution_clock::now();
	cout << "drawScene_bug()" << endl;
	auto timeStampNow = chrono::high_resolution_clock::now();
	auto elapsed = timeStampNow - timeStampPrevious;
	cout << chrono::duration_cast<chrono::microseconds>(elapsed).count() << endl;
	auto num = 100;
	while (elapsed > timeStampNow - timeStampPrevious)
	{
	chrono::duration_cast<chrono::microseconds>(elapsed).operator-=num;
	cout << chrono::duration_cast<chrono::microseconds>(elapsed).count() << endl;
	}
	

phil, I feel like you're chasing down a rabbit hole here with the timing thing. Even if you get the intricacies of chrono figured out, it doesn't solve the problem of the fact that you're still doing things wrong. Let's go ahead and look at your code in the original post (with some reformatting because damn, son):


void drawScene()
{
	glClear(GL_COLOR_BUFFER_BIT);
	drawScene_bug();
	TimerFunction(1);
	eraseScene_bug();
	// drawScene_bug_two();
	// eraseScene_bug_two();
	drawScene_ship();
	drawScene_bullet();
	glutSwapBuffers();
}

So, here you are trying to draw a scene. You start by calling glClear() (a good choice to start with). Then you apparently try to draw a bug. Then you call TimerFunction() to wait a little while. Then you apparently try to erase the bug you just drew, after which you draw a ship and a bullet then swap buffers.

 

Subsequent posts indicate similar errors in your thinking:


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();
}

Here, you clear the buffer (again, a good choice). Then you try to draw a bug. Then you try to wait for awhile. Then you try to draw a second bug. Then you draw a bunch of rows, a ship, a bullet, and swap buffers to display on the screen.

 

This just isn't how it works, man. Delaying for any amount of time before calling glutSwapBuffers() is completely and utterly pointless, serves no purpose whatsoever (except to make your drawing take longer than it needs to) and most definitely does not serve the purpose that you think it does.

 

Waiting in the middle of the drawing routine is pointless, because nothing you are drawing at this point is visible until you call glutSwapBuffers(). You're not drawing a bug, waiting for a bit, erasing it, and drawing it again. That's not what the player will see. Because until you call glutSwapBuffers(), the player doesn't see shit. It's all pointless. The time for waiting is after you swap buffers, and before you draw again. That's when you wait. 

 

Now, I know that people have spent a lot of time on trying to teach you this stuff over the last 14 years. (Man, how the time flies, eh phil?) I know that the money you apparently spent on getting your bachelors degree in computer science would probably have better been spent on buying a sweet monster truck to crush cars with or something. But man, you really ought to learn how to write a proper game loop. For a refresher, it looks something like this:


while running:
	Handle input
	Handle game logic
	Draw some shit
	Swap buffers
	Wait for awhile to limit frame rate
repeat

 It's not optimal in the slightest (dead waiting, such as what you're doing, probably isn't the best way to do things) but it's at least a place to start. Moving bugs, moving ships, etc... happens in the game logic part. After that you draw the shit and swap buffers which makes it visible. Then you wait (though, again, eventually you'd want to restructure your loop) before repeating it all over again. Until you figure out this basic pattern, then you're not going to make any progress on this, and no amount of dicking around with chrono and timers is going to make any difference, or do anything other than confuse the hell out of you even further.

well maybe I should do something simpler I have done pong and breakout, maybe space invaders is too complex.

Advertisement

I want to ask a simple question, how did you guys get so good at game programming?

7 minutes ago, phil67rpg said:

I want to ask a simple question, how did you guys get so good at game programming?

That's a simple question, but I don't think there is a simple answer.

That said, I generally think being good at something is a mix of "talent" and practice.

Talent means little without practice, and practice means little without talent. Talent in this case being the ability to learn, understand & make sense of abstract concepts and how they relate to programming and data flow.

---

You've spent a lot of time trying to practice programming -- 13 years or so based on your profile -- and you are still stuck at a very basic beginner's level, without understanding fundamental programming concepts.

Maybe you should consider the possiblity that your talents just don't lie in programming. Maybe your time is better invested doing something completely different? I don't know what that might be, but I honestly do not believe programming is you should invest more time on.

Hello to all my stalkers.

well I like to program just for fun. I want to work on a simpler project. do you have any ideas?

8 minutes ago, phil67rpg said:

well I like to program just for fun. I want to work on a simpler project. do you have any ideas?

No. I've given up on suggesting projects or explaning programming concepts to you.

Hello to all my stalkers.

This topic is closed to new replies.

Advertisement