我已经使用了CCSprite并且使用函数spriteWithFile
给出了项目中存在的图像。现在我想从服务器下载图像并将其加载到cocos2D游戏场景中的CCSprite中。什么是好的选择。请建议。cocos2D中图像的异步下载
我使用此代码,它不工作:提前
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://50.62.138.228:6026/1370user.jpg"]]];
NSURLResponse *response;
NSError *error;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
CCTexture2D *texture = [[CCTexture2D alloc] initWithData:responseData
pixelFormat:kCCTexture2DPixelFormat_RGBA8888
pixelsWide:50
pixelsHigh:50
contentSize:CGSizeMake(50, 50)];
sprite_Temp = [CCSprite spriteWithTexture:texture];
sprite_Temp.position=ccp(432,273);
[self addChild:sprite_Temp z:5];
感谢。
也许你可以从搜索“异步图像下载”开始?你试过什么了? –