SpriteBuilder中CCMotionStreak提示图片文件找不到

来源:互联网 发布:淘宝上怎么投诉店铺 编辑:程序博客网 时间:2024/06/08 15:10

今天写代码时遇到上述问题,代码如下:

player.streak = [CCMotionStreak streakWithFade:3.f minSeg:1 width:30 color:[CCColor whiteColor] textureFilename:@"ccbResources/ccbParticleSnow.png"];

运行出错,console中显示png路径不存在.

路径肯定是正确的.而且其他使用该图片的方法工作正常.
于是找到该方法:

CCSpriteFrame *frame = [CCSpriteFrame frameWithImageNamed:@"ccbResources/ccbParticleSnow.png"];

做断点,运行后进入该方法:

+(instancetype) frameWithImageNamed:(NSString*)imageName{    CCSpriteFrame* frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:imageName];    if (!frame)    {        CCTexture* texture = [[CCTextureCache sharedTextureCache] addImage:imageName];        frame = [texture createSpriteFrame];    }    return frame;}

发现并没有实际搜索磁盘上的文件,而是使用精灵帧缓存中的图片.所以有了下面变通的写法:

CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"ccbResources/ccbParticleSnow.png"];        player.streak = [CCMotionStreak streakWithFade:3.f minSeg:1 width:30 color:[CCColor whiteColor] texture:frame.texture];

这样就可以了.

0 0
原创粉丝点击