well, its smooth since you have a good computer =) I havent separated the physics update from the framerate simply because i couldnt get a satisfying result, just as you. So theres no magic going on here, nothing to see, move along! 😉 Everyone keeps referring to the "fix your timestep" article but im not sure how to solve the last step where youre supposted to interpolate between two steps.
Jungle action platformer (new version on pg. 6)
Games and ApplicationsI actually implemented the interpolation, but it didn't seem to help. I think it's because it's only interpolating for 1 frame (previous frame -> current frame), and that's not really enough to smooth out the motion if you've jumped several pixels.
It's entirely possible that I implemented it poorly and/or something else is the cause. Meh. I don't think I'm smart enough to actually fix it, but at least I am not alone in fighting this issue. 🙂
I have resorted to frame-locking, too. If your machine is slow, the game will slow down in that case, but that sure beats jittery movement for all cases, IMHO. Thanks for the info.
It's entirely possible that I implemented it poorly and/or something else is the cause. Meh. I don't think I'm smart enough to actually fix it, but at least I am not alone in fighting this issue. 🙂
I have resorted to frame-locking, too. If your machine is slow, the game will slow down in that case, but that sure beats jittery movement for all cases, IMHO. Thanks for the info.
Quote:
It's entirely possible that I implemented it poorly and/or something else is the cause. Meh. I don't think I'm smart enough to actually fix it
This was just my thought when i fiddled with it. Maybe one day we could summon the physics dieties of the box2d world and set it straigh. It might be bad practice, but now im not gonna waste more time on getting it right ... better frame locking than epileptic siezure-motion as we say
In other news, ive got some big updates going with this game
EDIT: published updates
Jungle Warfare:Survival
I wonder if I can help with your frame-rate woes. I recently trod that path, and eventually found the resources that helped me to end up with this (in Python):
It will call self.tick() at self.tickRate ticks per second, and then call self.render() as fast as it can. It also calculates the actual tick and frame rates. This code has worked perfectly for me so far.
Regarding interpolation before rendering, this is only necessary if your frame-rate exceeds your tick rate, at which point without it you will be rendering exactly the same thing several times over. Given that the tick rate is 60Hz, I don't see any need for interpolation.
Does that help?
EDIT: Btw, I really love your game. It's coming along very nicely indeed.
Code:
tickDuration = 1.0 / float(self.tickRate) # self.tickRate = 60
self.running = True
tickCount = 0
frameCount = 0
lastSecond = time.clock()
lastIterationTime = time.clock()
while self.running:
now = time.clock()
while lastIterationTime + tickDuration <= now:
self.tick()
tickCount += 1
lastIterationTime += tickDuration
self.render()
frameCount += 1
# Print the tick and frame rates averaged over the last second
elapsedSinceLastSecond = time.clock() - lastSecond
if elapsedSinceLastSecond > 1.0:
print "Ticks/second: ", tickCount / elapsedSinceLastSecond
print "Frames/second: ", frameCount / elapsedSinceLastSecond
tickCount = 0
frameCount = 0
lastSecond = time.clock()
self.running = True
tickCount = 0
frameCount = 0
lastSecond = time.clock()
lastIterationTime = time.clock()
while self.running:
now = time.clock()
while lastIterationTime + tickDuration <= now:
self.tick()
tickCount += 1
lastIterationTime += tickDuration
self.render()
frameCount += 1
# Print the tick and frame rates averaged over the last second
elapsedSinceLastSecond = time.clock() - lastSecond
if elapsedSinceLastSecond > 1.0:
print "Ticks/second: ", tickCount / elapsedSinceLastSecond
print "Frames/second: ", frameCount / elapsedSinceLastSecond
tickCount = 0
frameCount = 0
lastSecond = time.clock()
It will call self.tick() at self.tickRate ticks per second, and then call self.render() as fast as it can. It also calculates the actual tick and frame rates. This code has worked perfectly for me so far.
Regarding interpolation before rendering, this is only necessary if your frame-rate exceeds your tick rate, at which point without it you will be rendering exactly the same thing several times over. Given that the tick rate is 60Hz, I don't see any need for interpolation.
Does that help?
EDIT: Btw, I really love your game. It's coming along very nicely indeed.
Oh, Python. I love Python. Don't get to code in it much anymore, but one day....
In self.tick(), I assume you update physics? If so, how do you determine what step time to use? Or do you just step at a fixed interval?
I'll give this method a try later. Thanks for posting your solution!
P.S. I agree, the jungle game is a lot of fun. 🙂
In self.tick(), I assume you update physics? If so, how do you determine what step time to use? Or do you just step at a fixed interval?
I'll give this method a try later. Thanks for posting your solution!
P.S. I agree, the jungle game is a lot of fun. 🙂
zappBrannigan wrote:
EDIT: published updates
You forgot the "r" in Instructions. 🙂
Also, sometimes my keys would get stuck until I clicked the mouse to fire a shot.
Quote:
better frame locking than epileptic siezure-motion as we say
I have to agree with that 🙁 I just tried to correct the time step in a prototype where rendering tends to slow down at random moments. when I tried to advance time more for these moments, I had all sort of weird shit, for example falling objects never bounce, not even once. no, they DO bounce, but we dont see it, because when next frame comes, it has all already happened. So it looks like this only works well in one direction - when the game is happened to be played at high-speed computer, and you actually have to decrease time step. So IMHO the only solution is to cap time step. In terms of above python code, this would beCode:
while (lastIterationTime + tickDuration <= Math.min (lastIterationTime + maxTimeStep, now)) {
self.tick() updates the physics as:
It must be given a constant time step (1.0 / 60) in order to remain stable.
I have to say that I don't understand what's happening in your prototype makc. The minimum requirements of this algorithm are that the computer is able to update the physics at 60Hz with enough juice left to give you a decent visual frame-rate. If it's not able to maintain the 60Hz world update and a minimum acceptable frame-rate (15fps or something), then unfortunately you need either a new computer or a simpler physical\rendered world to simulate.
Code:
# Perform physics updates
self.world.Step(1.0 / self.tickRate, self.physicsIterations)
self.world.Step(1.0 / self.tickRate, self.physicsIterations)
It must be given a constant time step (1.0 / 60) in order to remain stable.
I have to say that I don't understand what's happening in your prototype makc. The minimum requirements of this algorithm are that the computer is able to update the physics at 60Hz with enough juice left to give you a decent visual frame-rate. If it's not able to maintain the 60Hz world update and a minimum acceptable frame-rate (15fps or something), then unfortunately you need either a new computer or a simpler physical\rendered world to simulate.
bb_vb, in the world of flash we are all confined to next-to-none CPU power + no GPU and so, especially when it comes to 3d, the rendering tends to be more time-consuming than physics 🙁
- new levels
- helicopter enemies (yay, boxes can fly)
- Finally solved the sticky-key problem
And theres a 1000 rounds/min surprise if you hit $100,000
- helicopter enemies (yay, boxes can fly)
- Finally solved the sticky-key problem
And theres a 1000 rounds/min surprise if you hit $100,000
Original thread: https://box2d.org/forum/viewtopic.php?t=936