Reputation: 109
I have problem with my game in Cocos2D (v2.0). I get two issues (I commented them in code parts). Here's Bullet.m file :
-(BOOL)checkCollisions:(CGRect)r
{
BOOL x = NO;
if(CGRectIntersectsRect([theGame myRect:self.mySprite],r)) //FIRST ISSUE - Sending 'id' to parameter of incompatible type 'CGRect' (aka 'struct CGRect');
//SECOND ISSUE - Instance method'-myRect:' not found (return type defaults to 'id')
{
x=YES;
[self reset];
}
return x;
}
And later in this file :
-(void)update
{
switch (self.whoFired)
{
case 1:
[self.mySprite setPosition:ccp(self.mySprite.position.x,self.mySprite.position.y + self.firingSpeed)];
for(Enemy * s in theGame.enemies)
{
if(ccpDistance(self.mySprite.position, s.mySprite.position)<30)
{
if([self checkCollisions:[theGame myRect:s.mySprite]]) //FIRST ISSUE - Sending 'id' to parameter of incompatible type 'CGRect' (aka 'struct CGRect')
//SECOND ISSUE - Instance method '-damage' not found (return type defaults to 'id')
{
[s damage];
}
}
}
break;
...
So, two errors are the same : Passing 'id' to parameter of incompatible type 'CGRect' (aka 'struct CGRect'). Those other two are about Damage and MyRect functions. Of course they exists (in GameScene.m and in Enemy.m files; everything is connected by .h files, and I get no errors in Damae and MyRect functions):
-(CGRect)myRect:(CCSprite *)sp
{
CGRect rect = CGRectMake(sp.position.x-sp.textureRect.size.width/2, sp.position.y-sp.textureRect.size.height/2, sp.textureRect.size.width, sp.textureRect.size.height);
return rect;
}
-(void)damage
{
self.hp--;
[self.mySprite runAction:[CCSequence actions:
[CCTintTo actionWithDuration:0.5 red:255 green:0 blue:0],
[CCTintTo actionWithDuration:0.5 red:255 green:255 blue:255],nil]];
if(hp<=0)
{
[self destroy];
}
}
What could be wrong? Why compiler can't see myRect and damage functions?
Upvotes: 1
Views: 140
Reputation: 22042
Why can't you use default boundingBox of CCSprite ?
if(CGRectIntersectsRect([self.mySprite boundingBox],r))
Upvotes: 1