Hello Guest

Author Topic: Taking a picture and adding it as a texture to a tk2dsprite  (Read 6392 times)

Peter

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Taking a picture and adding it as a texture to a tk2dsprite
« on: October 14, 2012, 02:14:54 pm »
Hi guys,

I recently started working with 2DToolkit and it is great! :)

Right now I am working on a game that utilizes the camera on the iPad and I would like to be able to at runtime, to take a picture and then add a small version as a thumbnail on a sprite.

What I am doing right now is I have four sprites loaded in with a placeholder texture on, and then as I take a picture I would like to replace that placeholder with the picture that I take. The picture that I take is in 600x600 resolution and the thumbnails is in 100x100 resolution.

The problem that I am facing right now is that when I chance the texture of the tk2dsprite at runtime it becomes stretches and blurry and doesn't fit.
The wierd thing is, if I use a normal unity plane the picture will resize perfectly to fit, but I would like to use the tk2dsprite, because I am in need of some of the functionality.

So my question is: How do I change the texture of a tk2dsprite at runtime and make sure that texture resizes to fit?

Here is the code where I change it:

Code: [Select]
thumbnailBoxes[currentActiveThumbnail].gameObject.renderer.material.mainTexture = frontCamTex;
Where ThumbnailBoxes is an array of 4 tk2dsprites.
I have also tried to change the texture using this command: sprite.GetCurrentSpriteDef().material.mainTexture
but that is giving me the same result as the other.

Hope my question is clear and that there is a solution :)

Thank you in advance
Peter

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Taking a picture and adding it as a texture to a tk2dsprite
« Reply #1 on: October 14, 2012, 05:03:09 pm »
If you change the texture it is going to be incorrect as the UVs will be referring to the original sprite wherever that may be in the atlas. What you wanna do is create a runtime sprite collection, and then use sprite.SwitchCollectionAndSprite to switch it to this newly created one.

Sample here:
http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,340.0.html

Its in the private support area, you will need to register your copy if you haven't already.

Peter

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Taking a picture and adding it as a texture to a tk2dsprite
« Reply #2 on: October 16, 2012, 10:52:08 am »
Hi Unikron,

Thanks for the help, this might be a silly question, but how will I go about registering my product?

Peter

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Taking a picture and adding it as a texture to a tk2dsprite
« Reply #3 on: October 16, 2012, 01:37:25 pm »