我有一个 xcode 项目,其中包含以下代码:
在 fflayer.h 中
int *芬贾尔;
在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。我不知道。谁能看到我可能做错了什么?
这是因为您的声明是一个指针,并且递增指针与递增 int 具有不同的含义(IIRC,它按 sizeof(int) 递增,我不确定)。
int *ffinjar;
// perhaps should be
int ffinjar;
编辑:我已经做了一个测试,确实增加一个指向 int 的指针在我的系统上增加了 4 (并且 sizeof(int) 也是 4)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)