Forum > C++ > How to use textureForKey ? ( Bug ? )

How to use textureForKey ? ( Bug ? )

By Woods Posted 2011-10-10 19:58 Comments 3
Woods
  • Posts: 5

A question about textureForKey.
Question code :

CCImage img = new CCImage;
img->initWithImageData;
CCTexture2D
tex = CCTextureCache::sharedTextureCache()->addUIImage( img, “catImage” );

if( CCTextureCache::sharedTextureCache()->textureForKey( “catImage” ) )
{
> > // find
}
else
{
> > // oh…no

> > // it run here
}

textureForKey don’t find “catImage”.
maybe I use way is wrong ?

Thank you.

zhangbin
  • Posts: 125
  • Location: Xiamen, China

#1 RE: 2011-10-11 01:19

Thanks for your feedback!
Yes, it’s a bug of engine! Issue #750 created for it.

The reason of this bug had been discussed in this topic:
http://www.cocos2d-x.org/boards/6/topics/2653?r=2982\#message-2982

And we only can fix this bug by modify the key with method CCFileUtil::fullPathFromRelativePath_ whenCCTextureCache::addUIImage()_ invoked.

Best wishes!

zhangxm
  • Posts: 2082
  • Location: Xiamen, China

#2 RE: 2011-10-12 18:44

Yes.
Woods Lin, you can add CCFileUtil::fullPathFromRelativePath() in CCTextureCache::addUIImage(), and do a test.
Share the result is better.

Woods
  • Posts: 5

#3 RE: 2011-10-13 06:04

thanks for help me.

And test is ok, I can get the CCTexture2D object.
but the way isn’t my think result.

because I own one file call “imageObject.data”,then it own many images in the data.

so I do:

// save the memory
>
loadImageFile( “imageObject.data” );
>
// get image from 0 index
>
BYTE rawData = getImageFromIndex;
>
CCImage
img->initWithImageData( rawData, width*height, CCImage::kFmtRawData, width, height );
>
CCTexture2D* tex = CCTextureCache::sharedTextureCache()~~>addUIImage;
>
// get image from 1 index
>
BYTE rawData2 = getImageFromIndex;
>
CCImage
img2~~>initWithImageData( rawData2, width*height, CCImage::kFmtRawData, width, height );
>
CCTexture2D* tex = CCTextureCache::sharedTextureCache()->addUIImage( img2, “imageName_2” );

but now “imageName_1” and “imageName_2” can’t so use, i must name it call “imageObject.data”.
because these images separated to memory address, then they don’t have separated to many files in the hard disc.

May give me some suggestions?

thanks.

Loggin to reply

Copyright © 2010 - 2013 Cocos2d-x.orgClustrmaps