Hi , i am using Chipmunk engine during one day , and i have trouble with "for" cycle
for(cpFloat time = 0; time < 2; time += timeStep)
{
..........
}
with that cycle my programm hang, but without this cycle game doesnt game physics, how to modernize this cycle? i use graphics game engine - HGE(haaf game engine) and Chipmunk, programing languege is C++, OS - Windows
Sorry for my english:)
update cycle
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: update cycle
If your game runs at a fixed framerate, (always at 30 or 60fps, etc) you can just do cpSpaceStep(space, 1.0/60.0), etc and that will probably work fine.
If you needed the physics to run smaller timesteps, you can do this:
I do those in a lot of my simple games and it works ok.
The best way to do it is to let your framerate and physics rate be different. Here is a good tutorial on how to do that:
http://gafferongames.com/game-physics/f ... -timestep/
If you needed the physics to run smaller timesteps, you can do this:
Code: Select all
int steps = 3; // step the physics 3 times every frame at 60fps
cpFloat dt = 1.0f/60.0f/(cpFloat)steps;
for(int i=0; i<steps; i++){
cpSpaceStep(space, dt);
}
The best way to do it is to let your framerate and physics rate be different. Here is a good tutorial on how to do that:
http://gafferongames.com/game-physics/f ... -timestep/
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 10
- Joined: Thu Jul 28, 2011 10:19 am
- Contact:
Re: update cycle
Hmm, no results, maybe chipmunk dont know that my CircleBody is dynamic_body , how to set that?
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: update cycle
Did you forget to call cpSpaceAddBody()?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 10
- Joined: Thu Jul 28, 2011 10:19 am
- Contact:
Re: update cycle
No i have written that : ballBody = cpSpaceAddBody(space, cpBodyNew(mass, moment));
i have written my code with Hello World Chipmunk(in official documentation)
i have written my code with Hello World Chipmunk(in official documentation)
-
- Posts: 10
- Joined: Thu Jul 28, 2011 10:19 am
- Contact:
Re: update cycle
OH my game is work, my variable timeStep=1.0f/60.0f was wrong, and i try to set in "hands" cpSpaceStep(space,1.0f/60.0f);
-
- Posts: 10
- Joined: Thu Jul 28, 2011 10:19 am
- Contact:
Re: update cycle
Wow, nice, you engine is good and simple:)
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: update cycle
Thanks. Glad you like it.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Who is online
Users browsing this forum: No registered users and 12 guests