Hi,
I am trying to do a CGRectIntersection to see if something has entered the screen area or left the screen area. Silly question but are CGRects set with a co-ordinate at the bottom left (i.e. not in the centre as per default anchor points)....i.e. creating a rect of x=0, y=0, width = 480 and height = 320......is good enough to use for my intersection test with a sprite bounding box?
-(void) update:(ccTime) dt
{
CGSize s = [[CCDirector sharedDirector] winSize];
CGRect winRect;
winRect.origin.x = 0; //(s.width/2.f);
winRect.origin.y = 0;// (s.height/2.f);
winRect.size.width = s.width;
winRect.size.height = s.height;
CGRect intersection = CGRectIntersection([self boundingBox], winRect);
if (!CGRectIsEmpty(intersection)) {
switch (state_) {
case kTargetOffScreenBefore:
[self setupFSMState:kTargetInPlay];
break;
case kTargetInPlay:
break;
default:
break;
}
} else {
switch (state_) {
case kTargetSpawning: // we have spawned but are yet to move on screen
[self setupFSMState:kTargetOffScreenBefore];
break;
case kTargetInPlay: // we are coming out of play
[self setupFSMState:kTargetOffScreenAfter];
break;
default:
break;
}
}
}