Hello Guest

Author Topic: Instantiated image on a plane in the row of a list does not act correctly  (Read 3918 times)

cloudchen

  • Newbie
  • *
  • Posts: 16
    • View Profile
Use the ScrollableArea to try to create a list like the ListView in Android platform. Trying to put a image on each row of this list, I manually created a template of the row item as a prefab then instantiated from it. However, the image looks like just overlapped at the 1st image (the prefab one). I checked through the inspector and everything seem act correctly. Just post my setting below:


I put the image on a plane object as one of children of the "RowItem" game object. The image download from Internet do show in the inspector correctly, but doesn't locate at the right position. In addition, the image doesn't scroll when I scroll the list. They just locate at the position where the image of prefab located.

Have no idea how to solve this problem. I think a workaround might be using a sprite to replace the plane? But I am pretty new to Unity and 2D Toolkit so that I don't know how can I download a image (.png or .jpg) from Internet and use it to replace the original sprite?!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
You can create a sprite at runtime easily enough, use tk2dSprite.CreateFromTexture to create it. Check the runtime sprite collection sample for a sample.

cloudchen

  • Newbie
  • *
  • Posts: 16
    • View Profile
Million thanks for your help, unikron. It does help me resolve this problem.

However, I have a tiny question about using a run-time created sprite. I just notice that it will create a lot copies of SpriteCollection when adopt this workaround. I got 4 tabs in a single scene, so that user could switch between them. Each time user click a tab, it will create tens of SpriteCollections and STILL ALIVE when user click other tab. The SpriteCollection keep accumulating in this level.



Would like to know if there is any way to handle those the auto-generated SpriteCollection?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
You should delete the sprite collection when you're done with the sprite.
Its as simple as GameObject.DestroyImmediate( sprite.Collection.gameObject );