Hello Guest

Author Topic: [Solved] Runtime sprite generation from texture, Behaviour and Performance  (Read 22252 times)

siroosec

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: [Solved] Runtime sprite generation from texture, Behaviour and Performance
« Reply #15 on: September 26, 2013, 10:28:24 am »
I'll try that! Thanks a lot!

siroosec

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: [Solved] Runtime sprite generation from texture, Behaviour and Performance
« Reply #16 on: September 26, 2013, 10:38:07 am »
By the way something just hit me!
Can I edit an existing collection's atlas textures and expect it to show new atlases properly?
Since all of my sprites are cards with same shape and dimension. So if I replace a single card in the atlas with another and then apply it, its place shouldn't be affected at all.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: [Solved] Runtime sprite generation from texture, Behaviour and Performance
« Reply #17 on: September 26, 2013, 11:55:12 am »
Yup thats correct

siroosec

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: [Solved] Runtime sprite generation from texture, Behaviour and Performance
« Reply #18 on: September 26, 2013, 01:16:10 pm »
Awesome!

Just one question! How can I find a sprite's corresponding atlas (I'm using multiple atlases) and corresponding area on atlas?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: [Solved] Runtime sprite generation from texture, Behaviour and Performance
« Reply #19 on: September 26, 2013, 01:42:02 pm »
its in the UVs. For runtime generated ones, there will be always 4 UVs, and it will be rectangular. For normal collections on the other hand, its a bit harder as there can be any number of UVs depending on how the sprite gets tesselated.

siroosec

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: [Solved] Runtime sprite generation from texture, Behaviour and Performance
« Reply #20 on: September 26, 2013, 01:51:57 pm »
I checked the UVs but they were floats so I thought they can't be it. So I suppose I have to multiply the UV numbers to atlas size right?
Also how can I get the right texture when I'm using multiple atlases?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: [Solved] Runtime sprite generation from texture, Behaviour and Performance
« Reply #21 on: September 26, 2013, 02:00:45 pm »
Yes, multiply by atlas dimensions to get pixel coordinates, get the right texture using spritedefinition.material.mainTexture

siroosec

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: [Solved] Runtime sprite generation from texture, Behaviour and Performance
« Reply #22 on: September 26, 2013, 04:45:02 pm »
I got it to work! I found Texture2D.PackTextures that packs all textures in one texture and returns their regions as Rect[]. (It uses a different convention for its Rects compared to what SpriteCollectionData.CreateFromTexture uses but its easy to convert it. Just convert coords from bottom-left based to top-left based and multiply rect variables by texture size.)

Just one problem remains. How can I make my collection to have colliders for its sprites?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: [Solved] Runtime sprite generation from texture, Behaviour and Performance
« Reply #23 on: September 27, 2013, 10:11:55 am »
It'll be easier to simply create your own colliders here, than to try to automate anything. Just adding a boxcollider after its created a mesh should create it at the right size...

hougenit

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Runtime sprite generation from texture, Behaviour and Performance
« Reply #24 on: December 04, 2013, 01:41:04 pm »
We happen to also be building a mobile card game using Tk2D :)

Trying to lump card textures together into a tk2d sprite collection likely isn't the best option (as you've noted) - you'd be loading in the atlas for mostly a single card.

We've gone down the route of an atlas-per card - which ups your draw calls since you won't be able to effectively batch them - but if we're talking about 40 draw extra calls for 40 cards, its probably fine unless you're targetting ancient hardware

It's probably wise to do the atlas generation offline rather than trying to do a .CreateFromTexture at runtime.



Have you solve the problem?I also have this problem,can you help me ?thank you