I'm using an NSMutableArray to keep track of all the bullets that are flying around in my game. The only trouble is, whenever I go to add a bullet object (an instance of the class Bullet I wrote to hold all the necessary data: speed, position, and damage) to my NSMutableArray, the simulator freezes and dies. Here's the relevant code chunks:
in GameScene.h:
NSMutableArray *bullets;
in GameScene.m:
-(id) init {
//Some other stuff
//I figured I should cast the array some how, and cause Apple's APIs didn't specify, I figured I'd make it with an object.
Bullet *cast = [[Bullet alloc] init];
bullets = [NSMutableArray arrayWithObject:cast];
[bullets removeLastObject];
}
-(void) addBulletPos:(CGPoint)pos Angle:(CGFloat)ang Speed:(CGFloat)vel {
Bullet *newB = [[Bullet alloc] init];
ang /= 180;
ang *= 3.14159;
CGFloat VelX = cos(ang)*vel;
CGFloat VelY = sin(ang)*vel;
[newB SetPosX:pos.x PosY:pos.y VelX:VelX VelY:VelY];
//All of these functions run fine, until this one, and then the whole thing crashes
[bullets addObject:newB];
}
What's wrong? How can I fix this?