预期标识符或'('

时间:2013-11-07 10:02:17

标签: ios objective-c cocos2d-iphone identifier

我似乎无法压制这个错误!

我正在开发一个小项目,试图为我的应用添加背景音频。在这个错误出现之前我做得很好。

.m文件第52行出错:

//
//  UDMenuScene.m
//  iLabyrinth
//
//  Created by Rolandas Razma on 5/12/10.
//  Copyright 2010 UD7. All rights reserved.
//

#import "UDMenuScene.h"
#import "UDPickMapScene.h"
#import "SimpleAudioEngine.h"
#import "UDHelpScene.h"
#import "iLabyrinth.h"
#import "CCDirector.h"

@implementation UDMenuScene
#pragma mark -
#pragma mark NSObject

- (id)init 
{
    if( (self = [super init]) )
    {
         [self addChild:[UDMenuLayer node]];
    }
    return self;
}

@end

@implementation UDMenuLayer
#pragma mark -
#pragma mark NSObject

- (id)init {

    if( (self = [super init]) )
    {
        [self setIsTouchEnabled: YES];
        CGSize _winSize = [[CCDirector sharedDirector] winSize];
        //AVAudioPlayer *player;
        NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"menu" ofType:@"mp3"]];
        NSError *error;
        player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
        // Add background
        CCSprite *sprite = [CCSprite spriteWithFile:[NSString stringWithFormat:@"menu%@.png", (isDeviceIPad()?@"~ipad":([iLabyrinth hightRes]?@"@2x":@""))]];
        [sprite setAnchorPoint:CGPointZero];
        [self addChild:sprite];
        _backgroundLayer = [CCSpriteBatchNode batchNodeWithFile:[iLabyrinth textureName]];
        [[_backgroundLayer texture] setAliasTexParameters];
        [self addChild:_backgroundLayer];
        // Add "Pay" button
        CCSprite *playSprite = [CCSprite spriteWithSpriteFrameName:@"play.png"];
            [playSprite setTag:MenuButtonPlay];
            [playSprite setAnchorPoint:CGPointMake(0.5f, 0.0f)];
            [playSprite setPosition:CGPointMake(_winSize.width /2, _winSize.height /2)];
        [_backgroundLayer addChild:playSprite];

        // Add "Help" button        
        CCSprite *helpSprite = [CCSprite spriteWithSpriteFrameName:@"help.png"];
            [helpSprite setAnchorPoint:CGPointMake(0.5f, 1.0f)];
            [helpSprite setTag:MenuButtonHelp];
            [helpSprite setPosition:CGPointMake(_winSize.width /2, _winSize.height /2 -[helpSprite boundingBox].size.height /2)];
        [_backgroundLayer addChild:helpSprite];
    }

    return self;
}


#pragma mark -
#pragma mark CCStandardTouchDelegate


- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    CGPoint touchPoint = [_backgroundLayer convertTouchToNodeSpace:[touches anyObject]];

    for( CCSprite *sprite in [_backgroundLayer children] ){
        if( [sprite tag] <= 0 ) continue;

        if( CGRectContainsPoint([sprite boundingBox], touchPoint) ){

            [sprite setColor:ccGREEN];
            [[SimpleAudioEngine sharedEngine] playEffect:@"click.caf"];

            switch ( [sprite tag] ) {
                case MenuButtonPlay: {
                    [[CCDirector sharedDirector] replaceScene:[CCTransitionSplitRows transitionWithDuration:1.0f scene:[UDPickMapScene node]]];
                    break;
                }
                case MenuButtonHelp: {
                    [[CCDirector sharedDirector] replaceScene:[CCTransitionSplitRows transitionWithDuration:1.0f scene:[UDHelpScene node]]];
                    break;
                }
            }

            return;
        }

    }

}


@end

这是我的.h文件:

//
//  UDMenuScene.h
//  iLabyrinth
//
//  Created by Rolandas Razma on 5/12/10.
//  Copyright 2010 UD7. All rights reserved.
//

#import "cocos2d.h"
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>

typedef enum {
    MenuButtonPlay =1,
    MenuButtonHelp,
    MenuButtonPlayHeaven,
} MenuButton;

@class player;

@interface UDMenuScene : CCScene {

}
@property (nonatomic, retain) AVAudioPlayer *player;
@end

@interface UDMenuLayer : CCLayer {
    CCSpriteBatchNode   *_backgroundLayer;
}
@end

1 个答案:

答案 0 :(得分:6)

您正在声明一个名为player的课程。

@class player;

(前言声明player是一种类型)

但您也使用player作为标识符

@property (nonatomic, retain) AVAudioPlayer *player;

(声明player的属性声明是AVAudioPlayer)的实例。

为防止出现类似错误,请永远不要声明名称以小写字母开头的类(改为使用Player),并使用自定义前缀来避免名称冲突(例如MYPlayer)。