Hi there, I've hit a brick wall (or at least a wooden one). I've had the majority of my game code running fine for a while now, but today I decided it was time to ad some animation to one of my sprites. Suddenly my collision detection, based on a simple CGRectIntersectsRect call won't work anymore. (It has been working fine until now). This is where I create my enemy-sprite:
CCSpriteSheet *devilSheet = [CCSpriteSheet spriteSheetWithFile:@"devilFlyer.png"];
CCSprite *devilSprite = [CCSprite spriteWithTexture:devilSheet.texture rect:CGRectMake(0,0,59,101)];
// A couple of random floats to vary the devil's position slightly
float x = arc4random() % 150;
float y = arc4random() % 300;
// sets the initial position of the devilSprite
devilSprite.position = ccp(320, -50+y);
// We need to create the actual animation of frames
CCAnimation *devilAnimation = [CCAnimation animationWithName:@"devilFlyer" delay:0.1];
int counter = 1;
while (counter < 48) {
// we need a string to held onto the name of the image
NSString *frameName;
frameName = [NSString stringWithFormat:@"devilFlyerFrame%i.png",counter];
CCSpriteFrame *nextFrame = [spriteCache spriteFrameByName:frameName];
[devilAnimation addFrame:nextFrame];
counter += 1;
}
// OK, now we have an animation defined,
// time to turn it into a usable action
//
// First we create an animate-action with
// the newly created animation (yes it's
// a bit over-complicated I agree!)
CCAnimate *devilAnimate = [CCAnimate actionWithAnimation:devilAnimation];
// Then we create a infinitely looping
// action to run through the animation
// again and again
CCRepeatForever *devilAnimationLoop = [CCRepeatForever actionWithAction:devilAnimate];
// which we run on the sprite (phew).
[devilSprite runAction:devilAnimationLoop];
...