How to get the image.png of a sprite

i’ve created a sprite
var mysprite =new cc.Sprite(res.image.png);
var img_url=“image data or imgurl”
i want to get the image url or image data to set it for a button…
please help!
thank you

res.image.png is the string your looking for thats all it is a string referencing the location of the image so just use that!

not the string, i want the data image… so that i can load that image to a uibutton…
please help…
thanks for the reply

@AbhyudaiRagh

Can you load res.image.png to uibutton?

If can, you may try to set res.image.png to the user data of the cc.Sprite and retrieve it for dynamic usage.

mysprite.setUserData(res.image.png);

mysprite.getUserData();

I think we can only get cc.Texture2D from cc.Sprite as mysprite.getTexture() or mysprite.texture.texture from the sprite.

For image data like base64, you may need to implement yourself.

1 Like

Thanks for the reply, it worked :smiley: