gpt4 book ai didi

ios - 预期的标识符或'('

转载 作者:行者123 更新时间:2023-12-01 17:41:00 25 4
gpt4 key购买 nike

我似乎无法解决这个错误!

我正在做一个小项目,试图将背景音频添加到我的应用程序。在出现此错误之前,我一直表现不错。

.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

最佳答案

您正在声明一个名为player的类。
@class player;
(向前声明说player是一个类类型)

但您也使用player作为标识符
@property (nonatomic, retain) AVAudioPlayer *player;
(属性声明说playerAVAudioPlayer的实例)。

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

关于ios - 预期的标识符或'(',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19832948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com