Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Velvety

Pages: [1] 2
1
Also, it seems like mixed layers of atlases and draw orders trigger extra draw calls even if the sprites don't overlap.  Is that how it works?  So for instance, your example of:

[  ATLAS0 ]   [ ATLAS1]   [ATLAS0]   [ATLAS1]
0 1 2 3 4 5    6 7 8         9               10

would still be 4 draw calls regardless if the sprites overlapped or not.  Is this this true? If so, why is this the case when they aren't even overlapping?

Thanks!

2
Thanks for the reply.  That's what I suspected.  Things start to get out of whack as soon as I have a few sprites from other atlases (units, animated buildings that couldn't fit into the main building atlas) drawing in between other layers.  But knowing how it works I can at least try to minimize how often that happens, to an extent.

Is there any way to control what order things are drawn within the same draw layer?  This must be happening somewhere, but I suspect it is deep within Unity and unaccessible?  For instance, if I had all of ATLAS0 drawing at layer 10 and then had some way of determining what order within that layer each sprite was drawn,  it seems like I could make significant draw call improvements.  But the best I can tell is that Unity draws them in the order they were first instantiated (I think).  If that is the case, my buildings can all be dragged around and moved by the user so that won't help me.  Any idea how one might access that order and modify it?  Is it even possible? Thanks.

3
Hi,

I am running into the same issue explained here: http://2dtoolkit.com/forum/index.php/topic,1756.msg8564.html.  Basically I have an isometric game with 2dToolkit with lots of overlapping buildings and troops, each set with a different draw layer to ensure they draw in the correct order so it looks isometric.  Even with all the buildings in 1 sprite atlas and no troops showing up I can get around 70 draw calls because (I think) the various overlapping sprites are all set to different draw orders.  Is that correct?

Am I doing something wrong, or is this just the nature of how it works?

Are there any ways to help reduce the draw calls for something like this?

4
Support / Re: Unload Textures
« on: November 06, 2013, 10:37:16 pm »
No its the reload thing that is causing the issue. Its a bug in Unity which I thought was fixed in 4.2 but clearly not. The reload textures function is only Reloading the first visible texture, thats all.

You could try this instead, its untested but it may work better...
Code: [Select]
void ReloadTextures() {
Texture tex = renderer.sharedMaterial.mainTexture;
foreach (Texture t in Collection.inst.textures) {
renderer.sharedMaterial.mainTexture = t as Texture2D;
}
renderer.sharedMaterial.mainTexture = tex as Texture2D;
}

That change did not seem to fix the issue.  Do I need to loop through animation frames or something?

5
Support / Re: Unload Textures
« on: November 06, 2013, 09:04:58 pm »
To get it to work on a multi atlas spanning sprite, you'd need to set this on every frame of animation. What version of Unity are you on, I thought they'd fixed this issue in 4.2?

I am on Unity v4.2.2f1 Pro.  To be clear, I am unloading all sprite collections between game transitions and then reloading everything I need for a specific area.  The pseudo code I am using looks something like this:

Code: [Select]
// first call DestroyImmediate() on all sprite gameObjects
...

// Now unload the sprite collection data textures
foreach (string key in spriteCollectionMap.Keys) {
spriteCollectionMap[key].spriteCollection.UnloadTextures();
spriteCollectionMap[key].spriteCollection.ResetPlatformData();
}

// clear the sprite collection map so there are no references left
spriteCollectionMap.Clear();

// now that everything is deleted ensure all the unused assets are removed, try to trigger the GC
Resources.UnloadUnusedAssets();

// now reload the needed sprite collection
tk2dSpriteCollection sc = (tk2dSpriteCollection)Resources.Load(collectionName, typeof(tk2dSpriteCollection));
if (sc != null) {
spriteCollectionMap.Add(new KeyValuePair<string, tk2dSpriteCollection>(collectionName, sc));
}

// load the unit (sprite) from the empty unit prefab and set its sprite collection
Transform unit = (Transform)Instantiate(emptyUnitPrefab, Vector3.zero, transform.rotation);

// get the sprite collection and set the sprite
tk2dSpriteCollection sc = spriteCollectionMap[0];
if (sc != null && sc.spriteCollection != null) {
        // get the tk2dsprite from our unit prefab
tk2dSprite sprite = (tk2dSprite)unit.gameObject.GetComponent<tk2dSprite>();
sprite.SetSprite(sc.spriteCollection, "spriteName");
// we must call ReloadTextures() to ensure the sprite texture is reloaded after any unloading has happened
sprite.ReloadTextures();
}


Am I missing anything in this process?  Thanks for your help.

6
Support / Re: Unload Textures
« on: November 06, 2013, 08:02:28 pm »
in tk2dBaseSprite.cs, add this function:
   public void ReloadTextures() {
      renderer.sharedMaterial.mainTexture = renderer.sharedMaterial.mainTexture as Texture2D;
   }

And in your game, when you need to reload a previously unloaded sprite texture, call ReloadTextures(). Calling this function repeatedly is fine.

This seems to work except for sprites with animations that span multiple sprite collections?  If I call ReloadTextures() on a sprite that spans a few sprite collections then the sprite texture flickers to  incorrect textures as it animates.  If I call ReloadTextures() on a sprite that has animations fully contained in only 1 sprite collection it seems to work fine.

What can I do to ensure sprites that span multiple sprite collections reload correctly?

Thanks!

7
Support / Re: Layout prefabs in UI_demo are missing a mono script?
« on: October 03, 2013, 06:30:25 pm »
Thank you, that worked! :)

8
Support / Re: Layout prefabs in UI_demo are missing a mono script?
« on: October 03, 2013, 04:12:40 pm »
I'm using Unity 4.2.1f4 and 2DToolkit v2.2.

The Integrity check turned up a few errors:

 File GUID does not match: Assets/TK2DROOT/tk2d/Code/Runtime/tk2dUpdateManager.cs
 File GUID does not match: Assets/TK2DROOT/tk2d/Code/Core/tk2dUICamerca.cs
 File GUID does not match: Assets/TK2DROOT/tk2d/Code/Core/tk2dUILayout.cs
 File GUID does not match: Assets/TK2DROOT/tk2d/Code/Core/tk2dUILayoutContainer.cs
 File GUID does not match: Assets/TK2DROOT/tk2d/Code/Core/tk2dUILayoutCotainerSizer.cs

I guess that means something went wrong with an update or something?  What's the best way for me to resolve this without losing all my current configured sprite collections?

9
Support / Layout prefabs in UI_demo are missing a mono script?
« on: October 02, 2013, 08:08:55 pm »
I have v2.2 and I'm going through the UI tutorial for the first time trying to use BasicButtons with a layout.

When I drag the BasicButton prefab (or any layout prefab it seems) from TK2DROOT/tk2dUIdemo/ControlPrefabs/Layout into my scene it has a missing mono script on it.  Also the parent Tk2dUILayoutContainerSizer does not recognize it (this is probably related).

What is the missing Tk2d script that needs to be attached to the layout button?

Thanks

10
Support / Re: Creating a sprite from code question
« on: September 18, 2013, 11:17:07 pm »
Interesting. I will try investigating the Resources.Load method you suggest.  Thanks for the info!

11
Support / Creating a sprite from code question
« on: September 18, 2013, 04:24:38 pm »
Hi,

I'm looking at ways that I can dynamically create a bunch of sprites when my game loads.  Ideally I want to be able to load a JSON or XML file from the network with a bunch of sprite configs that get dynamically instantiated into my game scene when it loads.

I've read your FAQ (http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,24.msg24.html#msg24) that mentions "If you need to generate large numbers of sprites by name, simply create one prefab for your sprite collection, instantiate it, and use GetSpriteIdByName() and switch the sprite. This way, you can pool one sprite type per Sprite Collection, and instantiate them the way you need it." 

This makes sense and currently seems to be the only way to handle doing what I want.  However, I'm curious if there is a way to create only 1 prefab with 1 sprite collection set (instead of having 1 prefab for every possible sprite collection) and then I can change the sprite collection using SetSprite().  To do this i would need a list of all the available sprite collections as accessible tk2dSpriteCollectionData objects.  I can not currently find a way to determine what all the available sprite collections are.

tk2dSystem seems to have a possible variable "allResourceEntries" that may be useful, but this is not accessible and I'm not sure if it is even useful for my needs.  Is there any way you can think of that would provide me with a static list of all the sprite collections?

12
Support / Re: sprite SortingOrder max layer?
« on: September 13, 2013, 06:09:06 pm »
Ok I've figured out how the SortOrder is working (by setting the mesh's bounds 0.01 units closer to camera).  I realize now that the max SortOrder is relative to how far away the camera is from the sprites (mine was -50 units away and so it could only see things up to about 50*1/0.01=5000 in SortOrder).

I've moved my camera back to -1000 so now it can show things up to about 1000*1/0.01=100000

I'm not sure if there is any potential down side to having that much space between the camera and the actual visible game units, but so far it works fine.

Thanks!

13
Support / sprite SortingOrder max layer?
« on: September 13, 2013, 05:01:12 pm »
I'm using 2D Toolkit to render my own isometric tiled map with tk2dSprites.  Drawing tiles in the correct order for isometric maps is very important for making sure it looks correct.  I am using the sprite's SortingOrder to do this, however it seems that any number higher than about 5000 makes the sprite disappear completely.   A SortingOrder of 4000 works fine.

My isometric tiled map has up to 26000 tiles and so up to 26000 render layers.  How come the support for SortingOrder seems to cut off around 5000?  Is this a bug or an intentional restriction?

The new editor variable for this is labelled "Sorting Order In Layer" does that mean I can group sprites into Unity Layers for further draw order control?  Or does that have to be done via Z axis manipulation?

14
Support / Re: tk2dCamera.ScreenExtents incorrect when ZoomFactor not 1?
« on: August 21, 2013, 05:06:56 pm »
Ya, that might be a cleaner way of fixing it for me.  Thanks for the suggestion I'll give it a try tonight when I get home! Will that be wasteful though, since tk2dCamera.UpdateCameraMatrix will be called at least twice per frame now?  Is there any kind of "isDirty" flag that is set to prevent it from reupdating the matrix multiple times?

15
Support / Re: tk2dCamera.ScreenExtents incorrect when ZoomFactor not 1?
« on: August 21, 2013, 04:42:13 pm »
So it looks like OnPreCull() is a Unity thing that is called before any camera determines what objects to draw in the frame.

Since I am only trying to call my bounds fixing function once for every zooming change, I am not catching the case of OnPreCull() being called afterwards and changing the extents again.  It seems like the extents are being updated every frame because they are recalculated from OnPreCull(), is that right?  I guess I will need to call my bounds fixing function every time that the extents change, so every frame.  I will give that a try and see if it fixes my issue.

If you have any suggestions on how I might call my bounds fixing function less often let me know.  Thanks.

Pages: [1] 2