HardCode
HardCode

Reputation: 2025

Incompatible type 'double'

I'm assigning a CGFloat animatedDistance and I'm getting this error.

Here I'm assigning value to animatedDistance

static const CGFloat KEYBOARD_ANIMATION_DURATION = 0.3;
static const CGFloat LANDSCAPE_KEYBOARD_HEIGHT = 140;

heightFraction is CGFloat as well.

if (orientation == UIInterfaceOrientationPortrait ||
    orientation == UIInterfaceOrientationPortraitUpsideDown)
{
   animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT * heightFraction);
}
else
{
    animatedDistance = floor(LANDSCAPE_KEYBOARD_HEIGHT * heightFraction);
}

What type should be animatedDistace? Can someone help me?

Upvotes: 2

Views: 1153

Answers (3)

Peter Hosey
Peter Hosey

Reputation: 96353

Sounds to me like you declared animatedDistance as holding some kind of pointer, such as NSNumber *, or a structure, such as CGSize. Either way, you can't assign a CGFloat there.

If animatedDistance holds an NSNumber object, create one around the value. Back when you asked this question, the way to do this was [NSNumber numberWithDouble:floor(…)]. Now, you can just use @(floor(…)).

If animatedDistance holds a CGSize or other structure, you're going to have to decide for yourself how to meaningfully convert from the single number you have to the kind of structure you want.

Upvotes: 0

mipadi
mipadi

Reputation: 410952

floor returns a double. On some platforms, CGFloat is a float. animatedDistance should be typed as a double (you can cast it to a CGFloat if needed).

Upvotes: 1

Gabriel
Gabriel

Reputation: 3045

Use this to get a vector... CGpoint vector = ccpSub(cgpoint 1, cgpoint 2); And if you want double/float values then do this:

CGpoint.location

for whatever you are trying to find the coordinates of, then assign a float to CGPoint.location.y and another float to CGPoint.location.x

You need cocos2d for this by the way. I think.

Upvotes: 0

Related Questions