Hello Guest

Author Topic: tk2dSprite.CreateFromTexture strange behaviour  (Read 8509 times)

sstublic

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
tk2dSprite.CreateFromTexture strange behaviour
« on: November 17, 2012, 08:17:26 pm »
Hi!

I'm a new user to 2D Toolkit and I have some strange issues with tk2dSprite.CreateFromTexture.
namely code:

Code: [Select]
tk2dRuntime.SpriteCollectionSize sz2 = tk2dRuntime.SpriteCollectionSize.ForTk2dCamera();
GameObject spr2 = tk2dSprite.CreateFromTexture(atlas, sz2, new Rect(0, 0, 300,300), new Vector2(0, 0));
spr2.transform.position = new Vector3(-200, -200, 0);

Is working FINE in Unity editor preview (the one when I press play button), but doesn't work when running PC standalone build. Not working meaning it doesn't show up on the screen.

I have one sprite in the scene added at design time and some gui elements to eliminate other problems and they both show up in both runtime environments. For some reason, this dynamically created sprite simply doesn't exist in PC runtime.

I'm sure there is something basically wrong I'm doing, but I'm confused because so far everything in Unity has been behaving consistently across different build targets.

Help please!

While at it, I need this for runtime topview map generation from tilesets. My idea was to group a block of tiles on the map and create a bigger texture (say 1024x1024) and then create sprite from this texture. Thus my map would be generated from smaller tiles, but would actually be rendered as several 1024x1024 sprites.
I tried making one tk2dSprite per tile, but ran into performance issues.
Any additional advice on this problem would be much appreciated!

Thanks!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dSprite.CreateFromTexture strange behaviour
« Reply #1 on: November 17, 2012, 08:23:50 pm »
How do you load atlas?

sstublic

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: tk2dSprite.CreateFromTexture strange behaviour
« Reply #2 on: November 17, 2012, 08:25:51 pm »
atlas is actually a
Code: [Select]
public Texture2D atlas;
I dragged my .png to the atlas property at design time.
So it's just an image containing tiles.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dSprite.CreateFromTexture strange behaviour
« Reply #3 on: November 17, 2012, 08:34:17 pm »
This looks like it is a bug. I'll post when I've got a fix. Drop me an email to support@unikronsoftware.com and I'll send a copy as soon as its ready.

sstublic

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: tk2dSprite.CreateFromTexture strange behaviour
« Reply #4 on: November 17, 2012, 08:41:39 pm »
Thanks for such a quick response. I'm still getting used and deciding about your product and such quick support is a great plus - regardless of bug :)


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dSprite.CreateFromTexture strange behaviour
« Reply #5 on: November 17, 2012, 08:46:56 pm »
Yay. Found the issue.
Its not really such a big issue. Basically the runtime code can't find the shaders because the shaders themselves aren't in a resources folder.

Basically, to fix this, move
TK2DROOT/tk2d/Shaders/*
into
TK2DROOT/tk2d/Shaders/Resources/*

Create a resources folder inside Shaders, and move all the shaders into that folder. The next version will have the layout corrected, but... there is a catch, Unity will NEVER move them from the folder they exist in currently.
So they will have to be done by hand on existing installations :(

I'll add a warning in the current codebase.

sstublic

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: tk2dSprite.CreateFromTexture strange behaviour
« Reply #6 on: November 17, 2012, 08:52:39 pm »
Thank you!