Leo Lou [bug] unnecessary path prepend in CCFileUtils::getFileData
Posts 53
Added by Leo Lou over 1 year ago

I am using CCTextureCache::sharedTextureCache()->addPVRImage("/data/data/com.mycompany/a_texture_file");
but CCFileUtils::getFileData prepends "assets/"
so the path become "assets//data/data/com.mycompany/a_texture_file"

It works in iOS, but not in android.

Bin Zhang RE: [bug] unnecessary path prepend in CCFileUtils::getFileData
Posts 62
Added by Bin Zhang over 1 year ago

Thanks for your feedback!
In the situation you described, you want to read a texture file which is not in assets directory.

Sorry that the methods in the engine only support read resource files in the assets directory of the apk file.
And the parameter of the function CCTextureCache::addPVRImage() should be the relative path of assets directory.

If you want read resource files in the system folders but not in the apk file, you must use fopen/fclose to implement that!
Or if you have much better ideas, welcome to share with us!

Francisco Morais RE: [bug] unnecessary path prepend in CCFileUtils::getFileData
Posts 6
Added by Francisco Morais over 1 year ago

Hi Bin Zhang,

I try load texture by fopen.... look this:

FILE * pFile;
long lSize;
char * buffer;
size_t result;
pFile = fopen ( "/mnt/sdcard/mms/test.png" , "rb" );
fseek (pFile , 0 , SEEK_END);
lSize = ftell (pFile);
rewind (pFile);
buffer = (char*) malloc (sizeof(char)*lSize);
if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}
// copy the file into the buffer:
result = fread (buffer,1,lSize,pFile);
CCImage image = new CCImage;
image.initWithImageData((void*)buffer, nSize, CCImage::kFmtPng);
CCTexture2D *texture = new CCTexture2D();
//texture->initWithImage(&image);
CCSprite *sprite = new CCSprite;
sprite->initWithTexture(texture);

But, if i add sprite into layer, he dont appear..... I can solve this problem??? do you help me please?

Minggo Zhang RE: [bug] unnecessary path prepend in CCFileUtils::getFileData
Posts 1641
Added by Minggo Zhang over 1 year ago

I think you should set the texture rect by CCSprite::setTextureRect().


(1-3/3)