Going back in time a bit?

Official forum for the Chipmunk2D Physics Library.
Post Reply
qkarx
Posts: 1
Joined: Sun Sep 19, 2010 1:39 am
Contact:

Going back in time a bit?

Post by qkarx »

I'm using the glorious chipmunk library in an iPhone game, and I want to save the state of the space on exit.
I do so by using SpaceManager (as well as storing other relevant values) when the app terminates, and it works perfectly. The only problem is that the app-terminate callback is only called a second or so after the home button was pressed, causing the game to save a state about a second ahead of when the user decided to quit. This can be problematic when the user re-opens the app and suddenly the game is over (this is a fast-paced game!)

My question is if it is possible to save the game state as it was about a second or so backwards in time? I've tried entering a negative value for cpSpaceStep, but it doesn't seem to work.

Thanks!
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Going back in time a bit?

Post by slembcke »

Unfortunately no, there is no way to reverse simulate physics.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
mobilebros
Posts: 90
Joined: Tue Aug 04, 2009 9:53 am
Contact:

Re: Going back in time a bit?

Post by mobilebros »

I wonder if (in your specific case) it'd be enough to loop over all relevant objects and just reverse their position (a tad!) using what you know about the velocity....
dieterweb
Posts: 176
Joined: Fri Feb 27, 2009 7:12 am
Location: Germany
Contact:

Re: Going back in time a bit?

Post by dieterweb »

Can you not just save the old positions/velocities/...? Maybe only save every n-th frame and interpolate the frames in between.
Visit our game Blog: [url]http://zombiesmash.gamedrs.com[/url] or follow us on twitter: [url]http://twitter.com/zombiesmash[/url]
bollu
Posts: 37
Joined: Tue Sep 14, 2010 4:33 am
Contact:

Re: Going back in time a bit?

Post by bollu »

Why not negate all values? That may work because physics depends on only "frame in time" (as far as i know but I'm only in 9th grade :D so I'm not sure). I don't know whether it'll work or not but It's worth a try!
jason_rogers
Posts: 81
Joined: Fri Aug 27, 2010 1:00 am
Contact:

Re: Going back in time a bit?

Post by jason_rogers »

I guess technically you could as bollu says rewind yourself by calculating all the physics in reverse, but if you go that far you could as well recode chipmunk ^^

dietweb solution seems the most likely from what you descibe, writting all the information of the shapes and bodies then when you reopen your app you'll have all you data.but then doing such a write would impact on the perf of your game even if you did it once evey second.

What I would like to bring up is the game design "flaw" I think originated this issue. if your game is such fast paced game as you put it, even if you managed to save 2 sec before in time, the time the user react s to the app having reopened he will have died again. I mean if so "little" time is important in the game, the user might get suprised being plunged in the fast paced so suddenly lol (I know it happens to me so often when playing I get back in the game without paying too much attention and bam... dead).

I find it strange this callback issue, I was thinking, ok there is a callback when the application closes, but is there a way to listen at the keys of the devices like volume up and down etc. if there is you could tirgger your own callback for saving

Hope this helps

jason
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests