Forum > C++ > [bug] unnecessary path prepend in CCFileUtils::getFileData

[bug] unnecessary path prepend in CCFileUtils::getFileData

By l4u Posted 2011-10-05 04:34 Comments 3
l4u
  • Posts: 54

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.

zhangbin
  • Posts: 117
  • Location: Xiamen, China

#1 RE: 2011-10-08 02:31

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!

busterkika
  • Posts: 6

#2 RE: 2011-11-08 09:17

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
// copy the file into the buffer:
result = fread ;
CCImage image = new CCImage;
image.initWithImageDatabuffer, nSize, CCImage::kFmtPng);
CCTexture2D**texture = new CCTexture2D();
//texture~~>initWithImage;
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?

zhangxm
  • Posts: 2081
  • Location: Xiamen, China

#3 RE: 2011-11-08 23:37

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

Loggin to reply

Copyright © 2010 - 2013 Cocos2d-x.orgClustrmaps