Problem With Motion in NSView
[NSDate timeIntervalSinceReferenceDate]
I've been trying this for a while now and I can't figure out how that works exactly. I know that returns the time since Jan 1, 2001 and I could (assuming this is allowed) subtract two of those to get my elapsed time. Is that how it's supposed to be done? Here's what I've been trying (but with no luck):
(edit: I figured out that all I had to do was make them doubles instead of floats and it worked. Thanks for the help. I'm going to leave this here for others.)
(edit: I figured out that all I had to do was make them doubles instead of floats and it worked. Thanks for the help. I'm going to leave this here for others.)
Code:
//don't use floats, they don't work
double newTime,lastTime,elapsedTime;
...
- (void)checkKeys
{
newTime = [NSDate timeIntervalSinceReferenceDate];
elapsedTime = newTime - lastTime;
lastTime = newTime;
if(up)
[myCharacter setY:[myCharacter y]+(5 * elapsedTime)];
if(down)
[myCharacter setY:[myCharacter y]-(5 * elapsedTime)];
if(left)
[myCharacter setX:[myCharacter x]-(5 * elapsedTime)];
if(right)
[myCharacter setX:[myCharacter x]+(5 * elapsedTime)];
[self setNeedsDisplay:YES];
}
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Motion Sensor Query for 3D game | iphone-query | 1 | 3,983 |
Sep 2, 2011 09:26 PM Last Post: PoseMotion |
|
| Device motion detection using Acceleration data. | RockyDilse | 4 | 7,053 |
Feb 16, 2011 12:57 AM Last Post: RockyDilse |
|
| Mouse Events in NSView | Chandhu | 1 | 3,559 |
Feb 28, 2008 02:08 AM Last Post: kuon_ |
|
| NSView loaded from bundle won't draw... | Joseph Duchesne | 1 | 3,129 |
Feb 12, 2006 03:33 AM Last Post: Cochrane |
|
| NSImage and NSView problems | Joseph Duchesne | 1 | 3,308 |
Aug 19, 2005 07:36 AM Last Post: unknown |
|

