Hi,guys
My engine version is 2.2.5
Now I want to useCCTextureCache::sharedTextureCache()->addImageAsync()
to load resource asynchronously but I wonder how I can get the key for the loaded texture in call back function.
void addImageAsync (const char *path, CCObject *target,SEL_CallFuncO selector)
this func adds a texture to texture cache asynchronously by path
of texture file and when loading done it calls the call back func and send the texture as a CCObject
param into call back
I use it to load several packed png
tuxtures and when loading done I want to addSpriteFrame
with their plist
files,but in call back func I don’t get the key
for the texture,so I can’t know which plist should be add.
This method loads the texture file itself. It’s not using a plist.
A plist would be used with an atlas. Why would you want to know the plist? Is the image also in an atlas?
The key is just the path you give to addImageAsync
.
You would need to implement getKeyByTexture
as in the JS version:
http://www.cocos2d-x.org/reference/html5-js/V3.0/symbols/cc.textureCache.html#getKeyByTexture
Sorry,I didn’t say it clearly.
That png is a atlas,something like atlas.plist
and atlas.png
I don’t use addSpriteFramesWithFile("atlas.plist")
because it’s not async.
I want to addImageAsync('atlas.png')
and get a CCTexture2D like someTexture
and use addSpriteFramesWithFile("atlas.plist",someTexture)
in call back func, so I need to know the plist name
This not something the C++ version of cocos2d-x supports at the moment.
As I said in my previous post, you would have to implement getKeyByTexture
like in the JS version.
The key of a texture given to the TextureCache
is just the string passed to addImageAsync
. In your case atlas.png
.
Why are you not just using a map and use atlas.png
as a key for atlas.plist
prior to calling addImageAsync? This way you can easily call addSpriteFramesWithFile
with the correct plist and your texture object.
In the call back what I get is only the pointer to the added texture,I don’t get the string “atlas.png” or “atlas.plist”.
So the map way won’t work.
But I think getKeyByTextur
way works,I will try it.
Thank you!
That’s why you save those values in the map prior to the callback.
Ah, yes. Sorry. I mixed addImageAsync
with another function, returning some id, but it’s void.