2012-06-01 4 views
0

Quel est le problème avec ce code?XCode 4, types incompatibles dans l'initialisation

-(float) getRotatingAngle : (CGPoint)firstPoint secondPoint:(CGPoint)secondPoint 
{ 
    float dx = firstPoint.x - secondPoint.x; 
    float dy = firstPoint.y - secondPoint.y; 
    float angle = CC_RADIANS_TO_DEGREES(atan2(dy, dx)); 
    return angle; 
} 

Un lorsque je tente de l'appeler comme ceci:

float ang = [self getRotatingAngle:projectile.position secondPoint:projectile.position]; 

je reçois l'erreur du titre. J'utilise cocos2d (COCOS2D_VERSION 0x00010001).

Le code se trouve à l'intérieur d'un gestionnaire ccTouchesEnded dans un CCLayerColor.

Toute aide appréciée.

EDIT: projectile est un CCSprite

EDIT: l'erreur du compilateur est (comme dans le titre) Incompatible types in initialization. TheLayer may not respond to '-getRotatingAngle:secondPoint')

TRUC: C'est mon collé copie le code d'un projet cocos2d, où il a travaillé. Juste que le projet était cocos2d V2. (?)

+1

avez-vous plus de chance si vous utilisez "' CGFloat' "et non pas" float "? –

+0

@Michael, non, toujours la même chose. –

+1

Mieux nous montrer comment projectile.position est déclaré. En outre, getRotatingAngle: secondPoint est-il déclaré avant d'essayer de l'invoquer? –

Répondre

1

Vous pouvez ajouter des définitions de méthode privée en haut de votre fichier .m, comme ceci:

@interface SomeClass() // Note the empty parens here 

-(float) getRotatingAngle : (CGPoint)firstPoint secondPoint:(CGPoint)secondPoint; 

@end 

Cela vous permet d'organiser vos méthodes plus tard dans la .m dans l'ordre que vous voulez.

0

Wow. Je viens de déplacer la méthode au-dessus du premier appel. Ensuite, cela a fonctionné. Extrêmement noobish.