8

I just decided to make the change from Slick2D to LibGDX. However, for me to be able to port my game over to LibGDX I need help understanding how to create textures in LibGDX from my game data files.

My game data files are encrypted and the images are encoded in base64 so I can keep them all in one txt file. How do I create a LibGDX texture from a ByteArrayInputStream.

In Slick2D I converted the base64 string into a bufferedimage. But I don't want to do that for LibGDX since I may want to get it on android soon.

EDIT: I just figured it out, kind of. I did it like so:

   Texture bucket;
    String base64 = "base64 string too long to paste"
    byte[] decodedBytes = Base64Coder.decode(base64);
    bucket = new Texture(new Pixmap(decodedBytes, 0, decodedBytes.length));

However, now the image is flipped vertically... Am I missing something?

Ike Yousuf
  • 81
  • 5
  • Welcome to Stack Overflow. Unlike many discussion boards, Stack Overflow is oriented around (single) questions and answers. Please post your "EDIT" as an answer (its okay to answer your own questions). See http://stackoverflow.com/faq#howtoask – P.T. Jun 03 '13 at 18:00
  • Thank you. I'll do that. it says: "Users with less than 10 reputation can't answer their own question for 8 hours after asking. You can answer in 7 hours. Until then please use comments, or edit your question instead." – Ike Yousuf Jun 03 '13 at 18:02
  • This link should help with the rotation part: http://stackoverflow.com/questions/9445035/rotate-image-clockwise-using-libgdx – Display Name is missing Jun 03 '13 at 18:06
  • Yeah I figured I could do that but I want the texture created right side up. Will flipping the byte array be the proper way? – Ike Yousuf Jun 03 '13 at 18:12
  • Solved. I created a sprite instead of a texture and flipped it. – Ike Yousuf Jun 03 '13 at 18:17

1 Answers1

2
Texture bucket;
String base64 = "base64 string too long to paste"
byte[] decodedBytes = Base64Coder.decode(base64);
bucket = new Texture(new Pixmap(decodedBytes, 0, decodedBytes.length));

That worked for me.

It was flipped because I changed the OrthgraphicsCamera to have 0,0 at the upper left.

Ike Yousuf
  • 81
  • 5