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;
    }

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

  • 相关阅读:
    序列化和反序列化
    抽象类与接口
    为了忘却的纪念
    gmail和hotmail也有企业邮局
    tag's tag
    在互联网上裸奔
    音乐网站,可以自己弹琴,歌谱整理
    今天看了ning的介绍,很有意思
    昨天服务器出现问题,解决过程如下所述
    google Trends
  • 原文地址:https://www.cnblogs.com/chenxiangxi/p/2279823.html
Copyright © 2011-2022 走看看