cocos2d游戏中xCode中出现意外的标识符错误

时间:2015-02-13 19:10:03

标签: ios objective-c

#import "MainScene.h"

static const CGFloat scrollSpeed = 80.f;

@implementation MainScene {
     CCSprite *_hero;
     CCPhysicsNode *_physicsNode;
     CCNode *_ground1;
     CCNode *_ground2;
     NSArray *_grounds;
     NSTimeInterval _sinceTouch;
}

- (void)didLoadFromCCB {
    _grounds = @[_ground1, _ground2];
    self.userInteractionEnabled =TRUE;
}

- (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
    [_hero.physicsBody applyImpulse:ccp(0, 400.f)];

}
   // _sinceTouch+=delta;
    _hero.rotation = clampf(_hero.rotation, -30.f, 90.f);
    if (_hero.physicsBody.allowsRotation) {
        float angularVelocity = clampf(_hero.physicsBody.angularVelocity, -2.f, 1.f);
        _hero.physicsBody.angularVelocity = angularVelocity;
    }



//position of hero
    - (void)update: (CCTime) delta {

    _hero.position = ccp(_hero.position.x + delta * scrollSpeed, _hero.position.y);
    _physicsNode.position = ccp(_physicsNode.position.x - (scrollSpeed *delta), _physicsNode.position.y);
// loop the ground
    for (CCNode *ground in _grounds) {

        // get the world position of the ground
        CGPoint groundWorldPosition = [_physicsNode convertToWorldSpace:ground.position];

        // get the screen position of the ground
        CGPoint groundScreenPosition = [self convertToNodeSpace:groundWorldPosition];

        // if the left corner is one complete width off the screen, move it to the right
        if (groundScreenPosition.x <= (-1 * ground.contentSize.width)) {
            ground.position = ccp(ground.position.x + 2 * ground.contentSize.width, ground.position.y);
            // clamp velocity
            float yVelocity = clampf(_hero.physicsBody.velocity.y, -1 * MAXFLOAT, 200.f);
            _hero.physicsBody.velocity = ccp(0, yVelocity);

            NSTimeInterval _sinceTouch;
            if ((_sinceTouch > 0.5f)) {
                [_hero.physicsBody applyAngularImpulse:-40000.f*delta];
            }

        }
        - (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
            [_hero.physicsBody applyImpulse:ccp(0, 400.f)];
            [_hero.physicsBody applyAngularImpulse:10000.f];
            _sinceTouch = 0.f;
        }
    }
}



@end

![错误] [1]

你好,互联网,

我是一名高中学生,对于我的高级项目,我正在制作一个脆弱的鸟类克隆,这将在几周后到期,我需要帮助解决代码中的一些错误,第一个是_hero的意外类型名称这一行// _sinceTouch+=delta; _hero.rotation = clampf(_hero.rotation, -30.f, 90.f);和意外的标识符或“(”在下一行。

此行还有- (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event {未声明的使用识别符“touchbegan”。

http://i.stack.imgur.com/qEZCc.png

1 个答案:

答案 0 :(得分:0)

// _sinceTouch+=delta;

_hero.rotation = clampf(_hero.rotation, -30.f, 90.f);
if (_hero.physicsBody.allowsRotation) {
    float angularVelocity = clampf(_hero.physicsBody.angularVelocity, -2.f, 1.f);
    _hero.physicsBody.angularVelocity = angularVelocity;
}

不在词汇范围内。周围没有任何功能。删除该代码或将其放在相关区域。

- (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
   [_hero.physicsBody applyImpulse:ccp(0, 400.f)];
   [_hero.physicsBody applyAngularImpulse:10000.f];
   _sinceTouch = 0.f;
}

限制在另一个被禁止的函数中。

之前将其移至右侧
@end

并且该错误将消失。