解析plist文件示例:由 plist 文件获取 sprite 动画的宽高

// 用于获取sprite的宽度和高度,太他妈蛋疼了~

-(CGSize) getAnimSpriteSize:(NSString*)animName {

NSString *plistPath = [[NSBundlemainBundle] pathForResource:animNameofType:@"plist"];

NSDictionary *dictionary = [NSDictionarydictionaryWithContentsOfFile:plistPath];

NSDictionary *framesDic = [dictionaryobjectForKey:@"frames"];

NSString *firstFrameName = [NSStringstringWithFormat:@"%@0.png", animName];

NSDictionary *firstFrameDic = [framesDicobjectForKey:firstFrameName];

NSString *rectDataString = [firstFrameDicobjectForKey:@"frame"];

NSRange range =NSMakeRange(1, [rectDataStringlength]-2);

NSString *withoutBorder = [rectDataStringsubstringWithRange:range];

NSArray *array = [withoutBordercomponentsSeparatedByString:@", "];

NSString *sizeString = [arrayobjectAtIndex:1];

NSRange range2 =NSMakeRange(1, [sizeStringlength]-2);

NSString *sizeStringWithoutBorder = [sizeStringsubstringWithRange:range2];

NSArray *size = [sizeStringWithoutBordercomponentsSeparatedByString:@","];

returnCGSizeMake([[size objectAtIndex:0]intValue], [[size objectAtIndex:1]intValue]);

}

你可能感兴趣的:(Sprite)