|
Updating game and input |
dothedru22
Member #7,325
June 2006
|
Hey I got my main game loop..and im not sure what should be updated using the fps time. I have it like this.
Im just wandering if the collision detection (not really in collision detection right now) should be with the input or drawing. like the jump checks and stuff in the Player update.. the reseting of variables etc. thanks for any help. not sure if it makes much sense. |
Kauhiz
Member #4,798
July 2004
|
I'm not sure if I understood your question. If you're asking when collision detection should be done, you should do it as a part of your logic. I don't know what the code you posted has to do with it, though. --- |
count
Member #5,401
January 2005
|
You HAVE TO do collision detection with the logic. Imagine this: So you walked through a wall because your collision detection has been skipped most of the time. The proper way it should be like this: Now you stand in front of the wall, where you should stand.
|
dothedru22
Member #7,325
June 2006
|
ok that makes sense..the problem is my game works fine most of the time..but when I have other programs running it slows the game down obviously. but instead of just running slower the player just doesnt jump that high. like ususally the player jumps pretty high..but if i have a lot of programs running it just jumps a tad.. it may have to do with the jumping code and what not..(not sure?) ..or maybe the order of how I check collisions...but for wall collisions , etc shouldnt that be checked in the actual move functions. (instead of being checked all the time) Quote: If you're asking when collision detection should be done, you should do it as a part of your logic. I don't know what the code you posted has to do with it, though. well. I was prolly gonna but stuff like : (is the player touching the ground? if he is not then put the player back on the ground) in the collision detection.. right now its with the input. but i assume it should be part of collision detection. |
Kauhiz
Member #4,798
July 2004
|
About the jumping, it could be that the player jumps as high, but the screen doesn't get updated, so the frame where he's at the full height of the jump never gets drawn. --- |
joshua.tilson
Member #7,552
July 2006
|
I don't have an answer for you unfortunatley, but i am experiencing similar problems. I have been working on a PONG type game, my first game, first real program etc. It works fine on my home computer but when i compile it and run it at work, it runs abysmally slow... |
count
Member #5,401
January 2005
|
When you write your code like the above example (which is pretty easy) your program will run with the same speed on any pc. Very important is to seperate logic and drawing.
|
dothedru22
Member #7,325
June 2006
|
see my problem is what to put in updateinput and what to put in updatedraw..because i have some code to stop the mouse.(like keep the mouse in a certain area.) when i put this code in the input(logic too) the mouse goes to far. if it put this code in with the drawing it works fine. see im pivoting a sprite based on the mouse movement so i need the mouse to stay within a certain range. the jumping collision is also messed up..sometimes the player goes to far beyond the ground. if i put this in the drawing its fine. thats why its not working out for me to put input and drawing seperate. im sure its something im doing wrong. couldnt be also that im passing a million pointers and stuff into every function.
although im sure hand coding that is not how it should be done. as i was typing this i came across the position mouse function and the mouse range function..oh well.. and i guess my game was wierd because i had my bps_timer setting at 150. i didnt know it should be at like 60. everything runs slower obviously but it seems to make the game smoother. |
Kauhiz
Member #4,798
July 2004
|
Your game should have 3 different parts; input, logic and output (mainly drawing). It sounds to me like you're missing the logic part alltogether. Stuff to do with the mouse you should have in your input part. Collision detection etc. goes into logic. Drawing should only have the draw functions, you should do any calculations necessary for drawing as a part of your logic loop. --- |
dothedru22
Member #7,325
June 2006
|
ok..yea that makes sense. but should logic be updated with the drawing or with the input. thats basically the question i have...thanks. |
Trent Gamblin
Member #261
April 2000
|
dothedru22 said: ok..yea that makes sense. but should logic be updated with the drawing or with the input. thats basically the question i have...thanks. Update your logic together with but after your input and separate from your drawing.
|
dothedru22
Member #7,325
June 2006
|
alright thats cool. thanks.. i got it now..the main thing was the fps and the way i was doing the mouse.. i was sortof hand coding what the position mouse and the set mouse range function did..so it really didnt work out..thanks..later |
|