【问题标题】:Xcode integer++ adding 4Xcode整数++加4
【发布时间】:2012-07-04 02:02:57
【问题描述】:

我有一个带有以下代码的 xcode 项目:

在fflayer.h中

int *ffinjar;

在fflayer.m中

-(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event {
    CGSize winSize = [[CCDirector sharedDirector] winSize];
    CGPoint touchLocation = [self convertTouchtoNodeSpace:touch];
    CGPoint oldTouchLocation = [touch previousLocationInView:touch.view];
    oldTouchLocation = [CCDirector sharedDirector] convertToGL:oldLocation];
    oldTouchLocation = [self convertoToNodeSpace:oldTouchLocation];

    CGPoint translation = ccpSub(touchLocation, oldTouchLocation);
    [self panForTranslation:translation];

    if (CGRectIntersectsRect(selSprite.boundingBox, eJar.boundingBox)) {

    selSprite.userData = FALSE;
    selSprite.visible = FALSE;
    selSprite.position = ccp(winSize.width +40, winSize.height + 40);
    _currentFlies--;
    ffinjar++;

 }

由于某种原因,这导致 ffinjar 添加 4 而不是 1。但 _currentFlies 只是减去 1。我不知道。谁能看到我做错了什么?

【问题讨论】:

    标签: objective-c xcode integer


    【解决方案1】:

    这是因为您的声明是一个指针,并且递增指针与递增 int 具有不同的含义(IIRC,它递增 sizeof(int),我不确定)。

    int *ffinjar;
    // perhaps should be
    int ffinjar;
    

    编辑:我做了一个测试,确实增加了一个指向 int 的指针在我的系统上增加了 4(并且 sizeof(int) 也是 4)

    【讨论】:

    • 你死定了。非常感谢。
    猜你喜欢
    • 2011-10-11
    • 2013-07-15
    • 1970-01-01
    • 2011-03-11
    • 2011-11-04
    • 1970-01-01
    • 2011-09-27
    • 2011-10-21
    • 1970-01-01
    相关资源
    最近更新 更多