zoukankan      html  css  js  c++  java
  • Cocos2D编程Xcode读取文件代码及其注释

    -(id) init
    {
    // always call "super" init
    // Apple recommends to re-assign "self" with the "super" return value
    if( (self=[super init])) {
    //step1:创建并获得一个指定文件路径test
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSLog(@"Documents文件路径:%@",documentsDirectory);
    NSFileManager *fileManage = [NSFileManager defaultManager];
    NSString *myDiretory = [documentsDirectory stringByAppendingPathComponent:@"test"];
    BOOL ok = [fileManage createDirectoryAtPath:myDiretory attributes:nil];
    NSLog(@"test文件路径:%@",myDiretory);
    //step2:设置需要读取的文件的绝对路径
    NSMutableString *myfilePath = [NSMutableString stringWithCapacity:100];
    [myfilePath appendString:myDiretory];
    [myfilePath appendFormat:@"/player2.png"];//Three.txt"];
    NSLog(@"myfilePath文件路径:%@",myfilePath);
    //step3:读取在test下的一个不在压缩包的图片文件 <路径怎么写:这里将myDiretory进行字符串的转换然后将其进行加减就可以了>
    NSData *data = [fileManage contentsAtPath:myfilePath];
    NSLog(@"文件内容二进制形式:%@",data);
    //step4:将这个不在包内图片内容进行显示
    //这里已经将图片给剪切了
    CCSprite *sprite = [CCSprite spriteWithFile:myfilePath rect:CGRectMake(0, 0, 28, 28)];
    sprite.anchorPoint = ccp(0, 0);
    [self addChild:sprite z:0];
    }
    return self;
    }

    以上代码详细的对怎样读取一个资源文件做了介绍,希望对大家有帮助。

  • 相关阅读:
    HDU 5875 Function 2016 ACM/ICPC Asia Regional Dalian Online
    LCA-tarjan understand 2
    LCA-tarjan understand
    MST-prim ElogV
    MST-kruskal ElogE+V
    transformjs 污染了 DOM?是你不了解它的强大
    检查浏览器支持Webp
    canvas实现平铺水印
    2016年总结--成长
    微信小程序体验(1):携程酒店机票火车票
  • 原文地址:https://www.cnblogs.com/chenxiangxi/p/2279823.html
Copyright © 2011-2022 走看看