Faster And Faster!
I am almost the only person that posts here in the obj-c secion......
every time i reopen a map the trolls run around faster and faster.
i know it is because i use [NSTimer and stuff here] more than once with out undoing the old one so they overlap... but how do i fix it?
CODES!
here is my open method all you need to know i think...
every time i reopen a map the trolls run around faster and faster.
i know it is because i use [NSTimer and stuff here] more than once with out undoing the old one so they overlap... but how do i fix it?
CODES!
here is my open method all you need to know i think...
Code:
- (IBAction)open:(id)sender
{
[trollObjects removeAllObjects];
numOfTrolls = 0;
numOfPads = 0;
NSString *lvl1 = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"lvl1" ofType:@"txt"]];
int a, b;
int index = 0;
for (a = 19 ; a >= 0 ; a--) {
for (b = 0 ; b < 20 ; b++) {
switch ([lvl1 characterAtIndex:index]) {
case '#':
enviro[b][a] = WALL;
objects[b][a] = WALL;
break;
case '@':
objects[b][a] = HERO;
xpoh = b;
ypoh = a;
break;
case '+':
enviro[b][a] = GRASS;
objects[b][a] = NONE;
break;
case '$':
objects[b][a] = BLOCK;
break;
case '&':
enviro[b][a] = GRASS;
objects[b][a] = NONE;
padPos[b][a] = PAD;
numOfPads++;
break;
case '*':
objects[b][a] = TROLL;
enviro[b][a] = GRASS;
[trollObjects addObject: [[[Troll alloc] initWithX: b Y: a] autorelease]];
numOfTrolls++;
break;
}
index++;
}
index++;
}
[self setNeedsDisplay:YES];
[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(moveTrolls:)
userInfo:nil
repeats:YES];
}
Save a pointer to the instance of the NSTimer you create. Then invalidate it before you create a new one.
The brains and fingers behind Malarkey Software (plus caretaker of the world's two brattiest felines).
ah yes i used the nonexistant -stop
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Parsing from a string to something faster? | Madrayken | 3 | 2,694 |
Aug 10, 2009 03:32 PM Last Post: smasher |
|
| Custom Primatives... faster? | KiroNeem | 26 | 6,609 |
Jan 8, 2006 12:52 PM Last Post: akb825 |
|

