I've only been using Obj-c for a week now, so bear with me, much of this may sound simple to you guys, and I may not understand the answers you give.
I'm trying to create a way of displaying objects in a single view for a game by drawing from PNG images using CoreGraphics.
I've created my own viewController that loads a custom view (CameraView) and draws to that view in scheduled loop:
In my CameraView, I alloc-init an NSMutableArray in the initialization. I also create my own drawRect method:
However, the CameraView isn't receiving the array that I passed from the ViewController. I get a warning saying that "objects is an unused variable" in my CameraView file. However, I have no idea what is wrong.
I'm trying to create a way of displaying objects in a single view for a game by drawing from PNG images using CoreGraphics.
I've created my own viewController that loads a custom view (CameraView) and draws to that view in scheduled loop:
Code:
//ViewController:
- (void)loadView
{
CameraView *playerView = [[CameraView alloc] init];
self.view = playerView;
[self initiateGame:(CameraView *)playerView];
}
- (void)initiateGame:(CameraView *)playerView
{
SceneObject *Player = [[SceneObject alloc] init];
Player.position.x = 100;
Player.position.y = 100;
Player.size.x = 64;
Player.size.y = 64;
Player.imageName = @"Player.png";
[playerView.objects addObject:Player];
[playerView checkObjects];
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(gameLoop) userInfo:nil repeats:YES];
}
- (void)gameLoop
{
[self.view setNeedsDisplay];
//I'll add more to this later after I solve this problem...
}
In my CameraView, I alloc-init an NSMutableArray in the initialization. I also create my own drawRect method:
Code:
//CameraView
- (void)drawRect:(CGRect)rect
{
// Drawing code
for (int i = 0; i < [self.objects count]; i++)
{
SceneObject *object = [self.objects objectAtIndex:i];
[[UIImage imageNamed:object.imageName] drawInRect:CGRectMake(object.position.x, object.position.y, object.size.x, object.size.y)];
[object release];
}
}
However, the CameraView isn't receiving the array that I passed from the ViewController. I get a warning saying that "objects is an unused variable" in my CameraView file. However, I have no idea what is wrong.