![]() |
|
Question about Timer - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: Graphics & Audio Programming (/forum-9.html) +--- Thread: Question about Timer (/thread-3115.html) |
Question about Timer - bonanza - Aug 6, 2007 11:49 PM Hi, i'am working on a Editor, and i like to move all Objects Timebased, here a snippet of my code: Code: /* Create an update timer */move my objects: Code: object.position+=velocity*deltaTime;Is this the right way?? Question about Timer - Nevada - Aug 7, 2007 03:34 AM Your move objects code is correct, but I didn't think you could just subtract pointer values like that. I believe you can cut some overhead by just doing this: Code: NSDate *clockTime = [[[NSDate alloc] initWithTimeIntervalSinceNow:0] retain];or something similar suiting your needs. I'm also assuming you have some kind of setNeedsDisplay or display call somewhere in the heartbeat selector. Question about Timer - OneSadCookie - Aug 7, 2007 03:51 AM They're NSTimeIntervals, not pointers. Also, you definitely don't want to create an NSDate object like that, and if you did, you definitely wouldn't want to overretain it ![]() I haven't thought whether the OP's code is OK or not, but yours is definitely not good
Question about Timer - Nevada - Aug 7, 2007 06:02 AM Bleh, I thought he was saying: start = [NSDate dateWithIntervalSinceReferenceDate]; Ignore me... That's what happens when you read too quickly (especially at 6:00AM).Anyway, what's wrong with having one static NSDate object? Does alloc:init automatically retain? I know if I use a convenience method the runtime complains because there is no auto-release pool available during static initialization. I sidestepped all of this and and just made a Clock class (more portable). Question about Timer - ThemsAllTook - Aug 7, 2007 06:07 AM That's one way to do it. Here's an article that demonstrates another way, and points out a few pitfalls of the variable interval approach: http://www.sacredsoftware.net/tutorials/Animation/TimeBasedAnimation.xhtml Question about Timer - Nevada - Aug 7, 2007 06:12 AM Oh, I see the problem now. Your deltaTime is only measuring how long it takes for you to render, not how long it has been since render was called (what you want). Rearrange it as follows: Code: start = [NSDate timeIntervalSinceReferenceDate];deltaTime is computed before end is set so it will be using the end set in the previous loop. You'll want to make sure that end is initialized to some value close (preferably equal to) start the first time around or you'll be sending an invalid deltaTime to your animate routine (which could throw your animations into an unexpected state before anything even starts). Question about Timer - bonanza - Aug 7, 2007 06:56 AM Nevada Wrote:Oh, I see the problem now. Your deltaTime is only measuring how long it takes for you to render, not how long it has been since render was called (what you want). Rearrange it as follows: Ah, thanks thats what i'am looking for ;-). one more question :-) i'am working on a simple particlesystem, in this i like to fade particle over a time here a snippet: Code: -(void)initParticles:(int)ii cant find whats going wrong here. when i using only one particle the system works as expected, more than one the system sucks, anyone know whats wrong?? thanks Question about Timer - ThemsAllTook - Aug 7, 2007 07:17 AM Not sure if it's your only problem, but if you want that call to glColor4d to affect the current particle you're drawing instead of the next one, you'll want to put it before the glVertex3f call. Question about Timer - bonanza - Aug 7, 2007 07:25 AM ThemsAllTook Wrote:Not sure if it's your only problem, but if you want that call to glColor4d to affect the current particle you're drawing instead of the next one, you'll want to put it before the glVertex3f call. damn its so simple, thank you.what you mean, with "only problem", you see more ??? Question about Timer - ThemsAllTook - Aug 7, 2007 10:22 AM All I mean is that I was only skimming, so although that was the only problem I noticed, I might have found more if I read the code more closely. Since it fixed your bug, though, maybe I wouldn't.
|