请耐心等待,我是一个新手,我第一次编写自定义初始化,sentance01text加载正常,所以我知道 plist 读取正常 :) 但我似乎无法让我的sentance01Timing计时工作><
这个方法应该传递用户输入的sentance01Timing,它是objectForKey,它应该将相关数组加载到audioIntervals数组中
目前我正在使用 NSString 访问字典并将其传递给数组audiointervals 但这似乎是错误的并导致错误任何帮助将不胜感激。我不明白为什么它对文本有效,但不是这个? 终止 - 原因:'-[__NSCFArray isFileURL]:
可能我在做一些非常愚蠢的事情><如果你可以请帮忙 ps 我不得不使用我的旧mac(我的好那个现在正在修理 - 所以将使用非弧 - 然后在我拿回我的漂亮mac时更新代码,所以请记住它为什么我现在不释放任何对象......)
你好世界.m
#import "HelloWorldLayer.h"
#import "TextWithAudioHilight.h"
@implementation HelloWorldLayer
+(CCScene *) scene
{
CCScene *scene = [CCScene node];
HelloWorldLayer *layer = [HelloWorldLayer node];
[scene addChild: layer];
return scene;
}
-(id) init
{
if( (self=[super init])) {
TextWithAudioHilight *pagetext = [[TextWithAudioHilight alloc]initWith5:@"test words here,\nmore words, more words.."
sentance01Timing:@"TimingSEN01"
withSoundNamed:nil];
[self addChild:pagetext];
}
return self;
}
- (void) dealloc
{
[super dealloc];
}
@end
TextWithAudio.h
#import <Foundation/Foundation.h>
#import "cocos2d.h"
@interface TextWithAudioHilight : CCLayer {
}
@property(nonatomic,retain)NSString *sentance01text;
@property(nonatomic,retain)NSString *sentance01Timing;
@property(nonatomic,retain)NSString *soundNamed;
-(id)initWith5:(NSString *)sentance01text sentance01Timing:(NSString *)sentance01Timing withSoundNamed:(NSString *)soundNamed;
@end
TextWithAudio.m
#import "TextWithAudioHilight.h"
@implementation TextWithAudioHilight
@synthesize sentance01text = _sentance01text;
@synthesize sentance01Timing = _sentance01Timing;
@synthesize soundNamed = _soundNamed;
-(id)initWith5:(NSString *)sentance01text sentance01Timing:(NSString *)sentance01Timing withSoundNamed:(NSString *)soundNamed
{
self = [super init];
if(self)
{
CGSize size = [[CCDirector sharedDirector] winSize];
NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"AudioTimings" ofType:@"plist"];
NSDictionary* myDictionary = [NSDictionary dictionaryWithContentsOfFile:plistPath];
//needs create array that has timing information as an array from the plist
//NSString *Text01timing = [myDictionary objectForKey:@"sentance01Timing"];
NSString *Text01timing = [myDictionary objectForKey:_sentance01Timing];
NSMutableArray * audioIntervals = [NSMutableArray arrayWithContentsOfFile:Text01timing];
NSLog(@"Text01timing %f",audioIntervals);
//needs to create a label and put the text in it
CGSize maxSize = {800, 200};
CGSize actualSize = [sentance01text sizeWithFont:[UIFont fontWithName:@"Helvetica" size:20]
constrainedToSize:maxSize lineBreakMode:UILineBreakModeWordWrap];
CGSize containerSize = { actualSize.width, actualSize.height };
CCLabelTTF *label = [CCLabelTTF labelWithString:sentance01text dimensions:containerSize
alignment:UITextAlignmentLeft fontName:@"Helvetica"
fontSize:20];
// Center label
label.position = ccp( size.width /2 , size.height/6 );
label.color = ccc3(80, 80, 80);
// Add label to this scene
[self addChild:label z:7];
}
return self;
}
@end
AudioTimings.plist
<plist version="1.0">
<dict>
<key>TimingSEN01</key>
<array>
<real>0.044444</real>
<real>0.143054</real>
<real>0.213886</real>
<real>0.48055</real>
<real>0.844434</real>
<real>1.345817</real>
<real>1.470816</real>
<real>1.577759</real>
<real>2.020809</real>
<real>2.331917</real>
</array>
</dict>
</plist>