views:

80

answers:

2

Hi. I try to call a method with a float parameter but the value the method gets is not what I sent.

Here is the code for the call (the actual call is the last part of the last line, [child setFaceDirection: direcao]; ):

direcao = dirRadianos * 180 / M_PI; // direcao = The value I send

NSLog(@"Value Sent:   %f", direcao); // Log what I'm sending

for (CCNode *child in super.children)  if([child respondsToSelector: @selector(setFaceDirection:)]) [child setFaceDirection: direcao];

Here is the code for the Method:

-(void) setFaceDirection: (float) angle {
    NSLog(@"Value Recieved: %f", angle);
    [theSprite setRotation: - angle ];
}

Here is the declaration of the float variable direcao

@interface PersControlNode : CCNode <CCTargetedTouchDelegate> {
            // ...
        float direcao;
           // ...

}
//  ...
@end

Here is the output from NSLog:

Value Sent:       -16.699266
Value Recieved: 0.000000
Value Sent:       -16.699301
Value Recieved: 36893488147419103232.000000
Value Sent:       -16.699625
Value Recieved: -0.000000
Value Sent:       48.366463
Value Recieved: 2.000000
Value Sent:       48.366451
Value Recieved: -36893488147419103232.000000
Value Sent:       48.366428
Value Recieved: 0.000000
Value Sent:       48.366444
Value Recieved: -0.000000
Value Sent:       14.036244
Value Recieved: -0.000000
Value Sent:       14.036238
Value Recieved: -2.000000
Value Sent:       14.036201
Value Recieved: -36893488147419103232.000000
Value Sent:       14.036191
Value Recieved: -0.000000
Value Sent:       14.036273
Value Recieved: 36893488147419103232.000000
Value Sent:       12.528809
Value Recieved: 0.000000
Value Sent:       12.528766
Value Recieved: 36893488147419103232.000000
Value Sent:       12.528852
Value Recieved: -2.000000
Value Sent:       12.528863
Value Recieved: 0.000000
Value Sent:       -101.309929
Value Recieved: -36893488147419103232.000000
Value Sent:       -101.309860
Value Recieved: -2.000000

What am I doing wrong? I'm new to Objective C. Thanks to anyone who tries to help.

PS. It works better if I use int instead of float, but even then, there are still some errors.

A: 

I believe this has to do with automatic type conversions from the compiler's side, but someone more knowledgeable about C will have to explain it. To fix the problem, change the type of the angle parameter to double.

Felixyz
Thanks...I will try that
Jose
A: 

Do you have any other methods called setFaceDirection: that take different types?

Do you have zero compiler warnings?

mustISignUp
Hi.. I have other methods called setFaceDirection but they also take floatsThe only warning I used to get is "CCNode may not respond to setFaceDirection", witch is true, thats why I check is it responds first.But now that I converted all to int, the warning is gone...
Jose
Just clarifying: I had some classes with setFaceDirection: (float) angle {..}. They all took float. Then, because of this problem, I changed everything to int and it is (kinda) working. But I have to be able to pass floats as parameters none the less. Interesting thing the warning is gone when everithing is int. I had not noticed that until now. Thanks man.
Jose