No, I'm not using any kind of zooms. I was messing around with the CCLayer's bounding box, trying to figure out how to solve the problem using that. I have a HALF of a solution. I'm not exactly sure why it only works half way. The way I currently have it set up, it detects correctly if the enemy is on the screen, but if I move my character past the enemy (my x coordinate is greater than his), it says the enemy is off the screen.
I'll show you some code. The following is called within the layer's update method:
// Update each of the enemies
for (Enemy *enemy in enemies)
{
if ([enemy isOnScreen:self.boundingBox])
{
[enemy update];
NSLog(@"enemy on screen");
}
else
{
[enemy stopMoving];
NSLog(@"enemy off screen");
}
}
And here's the method within the CCSprite that is being called to check whether the enemy is on the screen:
-(BOOL) isOnScreen:(CGRect) screenBox
{
CGPoint location = [[CCDirector sharedDirector] convertToGL: self.position];
screenBox.origin.x = (-screenBox.origin.x) + windowWidth/2;
screenBox.origin.y = (-screenBox.origin.y) + windowHeight/2;
if (CGRectContainsPoint(screenBox, location))
return YES;
else
return NO;
}
As you can see, I had to mess with the origin of the rect in order to get it to work at all. Like I said, it works for half of the screen, but for some reason, when the enemy enters the left half of the screen, it stops working.
Any ideas as to what is going on? I'm truly confused by the CCLayer's bounding box coordinates. They don't really make sense to me.