Jump to content

Convert a Sprite into Base-64


botoman
 Share

Recommended Posts

Hi,
Do you know if it's possibile to convert a Sprite or a Texture into Base-64 format in Panda?

E.g.
 

//var image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4gcKEAkwofgEyAAAApJJREFUSMe1Vj1rKkEUnRk1loYVFtIFxEIWRANB7IKNCBYWsYliYam/wEDyCwIRIVjaKEEt0iSghdgsUcg2Spr41UkiuySYkMKNmU0xvH378vJ2d9R3qnXWuefunXPPHagoCvifQOb/+vLysrOzw3Hcx8cHBYNiDrIsb29vI4QQQi6XSzENswTBYBD9AoTw6OhokwTFYhEAgDQAADSbTTN7oeEhL5dLm81GgmrhcDien583cMi5XA5C+OOZX1xcGG43/gIIIUkfY/w7L4QAAAzDiKK41heUy2XygDGuVqukrPl8npBJknR7e7uWTCORCJHN6empoijpdPr4+FhRlEQiQU47k8mspSJVM+12u1KpkJzu7+9LpRIplGFP6JVIFEW17v1+PxqN7u7uBgIBjuN6vR4hHo/Hq5eo2+2q8t/a2hoOh2Sd53l1HQAwm810glh1uF9fX7Xd4Ha7PR7PYrGYTCbatpjP5yzL/iuIHoHV+sdbhNDDw4Oq0W+SpS6RIAh2ux0ZwWKxOByO0WhEp6Krq6tv5qMPAADP82a9SJZlkjvVYIEQLpdLU51cq9VWmFyfn5+NRsMUwfv7+2rTUas6PYL9/f3VCHw+n1k3VR3UPDDGP4ZChrlgjP1+v9aryeLe3p520ev1Utj1wcGBGiibzQqCMBgMYrEYwzAsyyYSicfHx7u7u1QqpXIEg0GKRru5uSFvC4WCvlmenZ2pk4POri8vLzudDnk+Pz+Px+OtVksUxaenp+vr63A4XK/XVe8rFotr3SqSyeTf/nNycmJmr5WqV8n0p7ptIpMSdDqdfr+f/AyFQgihb7pa6+o4n8/f3t7U+T6dTiVJWiwWm7w6Evh8vsPDQ6otkKqgGGPaDv8CndB2NBjOv0gAAAAASUVORK5CYII=';

We need it for Facebook Instant Games Update Async.

Thanks
Alessio

 

Link to comment
Share on other sites

Hi @botoman

Yes that should be possible. You would have to first create empty canvas element and draw your sprite's texture into it, then convert it into Data URI.

var sprite = new game.Sprite('panda.png');

var canvas = document.createElement('canvas');
canvas.width = sprite.width;
canvas.height = sprite.height;

var context = canvas.getContext('2d');
context.drawImage(sprite.texture.baseTexture.source, 0, 0);

var data = canvas.toDataURL();

To create Sprite from Data URI you can just pass it as a parameter:

var sprite2 = new game.Sprite(data);

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...