Is there possiblility that running 2 loops at the same time using C++?

Started by
18 comments, last by Athelena 19 years, 11 months ago
quote:Original post by Athelena
Basically, i have multiple loop within a single loop, but some i need to run at the same time, just dont know how to do it...


That''s the wrong way of doing it. You don''t need multiple loops to move your objects. One loop will do the job. Re-read my post.

And look up in the articles section if my example isn''t clear enough.
[size="2"]I like the Walrus best.
Advertisement
Perhaps you could just keep track of the bullets in a dynamic list (or limit the bullets for easier coding =))

That way when you draw your screen you move the bullets x,y then store that and draw the bullet on the screen.

Btw, when you say ''wait for user input'', are you stopping the loop until user input comes in? If so, investigate ways to not do that (eg peekmessage).
for my case, the Alien Ship is not in the "Pending for user input" loop, it's another loop.

The "Pending for user input" loop is for the user to press "left,right,spacebar" in order to perform some actions - move left,right, and shot.

Therefore, it's 2 different loop, and i wanted both to run togethers~

emm~~... can provide me some code please...?

ty for your information and help
~Smile~

[edited by - Athelena on May 8, 2004 5:05:33 AM]
you can get banned for doing this if you are bugging on purpose.
[size="2"]I like the Walrus best.
What you mean "bugging on purpose"? actually, i''m new to this forum, just sign up today, so still i dont know the rule here.
You have to ask yourself, "Wouldn''t it be easier to actually query and process the input and move the bullets/aliens/ship in the same main loop?"

A hint: yes...

Kind rgds,
-Nik

Niko Suni

Click here. This probably isn''t what you are looking for, but in may give you some ideas. Like all of the enemy movements could be handled in the process method and input could be handled in the input method, and so on. The goal of programming in modern operating systems is to share. what you need to do is instead of getting two loops to run concurently, they both need to update a little bit, then return control to the system.

Btw, what OS, and what API?
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
quote:Original post by Athelena
dear owl:

I''ve done the part already......currently i only missing the Alien Ship moving while my bullets shot out

ty for your information and help


whoa... I didn''t see this one. Sorry.
[size="2"]I like the Walrus best.
Ah, I think the key to remember is that everything should be given a chance to do any movement or processing that it needs to do *before* the next frame is drawn. That will allow multiple things to be able to move at the same time, which is what it sounds like you want.

In reality (as in looking at it from the pre processing), one is moving before the other. But since all that pre-processing happens before it is rendered to the screen, and any reactions that must take place because of those interactions also happens before it is rendered to the screen, the result is that the end user, even if the end user could flip through one frame at a time at his leisure, would never know that and they are in fact effectively happening at once.

I hope that helps!
-Vendal Thornheart=) Programming for a better tomorrow... well,for a better simulated tomorrow. ;)
Thx to everyone''s help and infomation

Now I''ll to do it....but using the information that you all given..

Once again, ty very much

This topic is closed to new replies.

Advertisement