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 - aikitect

Pages: [1]
1
Nevermind figured it out.  I searched up another thread and found that I needed to turn on premultiplied alpha and set the shader to PreMulVertexColor.  Also, the weird pixels I saw were because I didn't include padding into my algorithm for generating the atlas texture.  Once I did that, everything worked.  Thank you so much for your help, this is amazing! :)

2
Great, I got it to work.  Now I'm running into one (hopefully) last issue.  When I actually output the character onto the screen, I get the attached image.  If you look closely, you will see a white outline around each body part of the character (the arms are a good example).  In addition, there are white pixels that appear above the left ear and to the right of the right ear that are not part of the source image.

Why is this happening?  I did some reading on it, and my hypothesis is that it is related to the shader that is used to create the RenderTexture.  Do you have any idea how I can fix this?

3
I have a Spine SkeletonAnimation that uses this new SpriteCollection to generate a character using the sprites in the SpriteCollection.  When I use a pre-built SpriteCollection that I created via the Editor, the character shows up on the screen.  However, when I create the SpriteCollection via CreateFromTexture, nothing shows up at all on the screen.

4
Great, I got the RenderTexture working.  Thank you so much!  Now the last part is trying to get the right regions and anchors for each of the sprites.  So using my packing algorithm, I get back a list of Rects that contain the bounds of each sprite.  For example, I will get back one Rect myRect that is:

x: 466.0
y: 84.0
width: 42.0
height: 34.0

(This is using the bottom left as the origin.)

I am trying to translate this into the the region and anchor (preferably centered) that is given to tk2dSpriteCollectionData.CreateFromTexture.  I have tried sending the following but they don't work:

Code: [Select]
region = myRect;
anchor = myRect.center;

region = myRect.NormalizeBy(100.0f); // This divides each dimension of the Rect by 100.0f.
anchor = myRect.center / 100.0f;

Also, my CreateFromTexture call is as follows:

Code: [Select]
spriteCollection = tk2dSpriteCollectionData.CreateFromTexture(atlasTexture,
tk2dSpriteCollectionSize.PixelsPerMeter(100.0f), allSprites, spriteRegions, spriteAnchors);

5
Hey, so I'm in the middle of implementing RenderTexture-based atlases.  I have the following code that creates a RenderTexture:

Code: [Select]
    private Texture2D CreateAtlasTexture(int textureSize)
    {
    RenderTexture renderTexture = new RenderTexture(textureSize, textureSize, 24);
    Texture2D atlasTexture = new Texture2D(textureSize, textureSize, TextureFormat.ARGB32, false);
   
    RenderCamera.aspect = 1.0f;
    RenderCamera.targetTexture = renderTexture;
    RenderCamera.Render();
   
    RenderTexture.active = renderTexture;
                atlasTexture.ReadPixels(new Rect(0.0f, 0.0f, textureSize, textureSize), 0, 0);
                atlasTexture.Apply();
    RenderTexture.active = null;
    RenderCamera.targetTexture = null;
   
    return atlasTexture;
     }

However, when I run this code, and the camera preview looks like the screenshot below, I get a Texture2D that is distorted.  Can you help identify why this might be happening?  I feel like it is a camera setting (it seems like it is being previewed at 1024x768 and shrunk to 512x512), but I'm not sure how to fix this.  Thanks!


6
Thanks, what exactly makes Texture2D.PackTextures slow in the first place?

7
Be sure to only draw this once and not repeatedly.  How do I ensure that I only draw the texture once?

One thing to note - if your modify the atlas in such a  way that existign sprites will no longer be valid, you will need to find them and call ForceBuild to have them regenerate the geometry.  What would I be calling ForceBuild on?

8
Ok, so if there's no sample code, can you give guidance on the following rough algorithm?

1) Create a RenderTexture called characterTexture.
2) Create a camera in the scene. (Should this camera be a tk2dCamera?)
3) Pack the relevant 2D sprites into the field of view of the camera.  Save the sprite names in names, save the width and height of each sprite in regions, and save the center (since they are center-anchored) of each sprite in anchors.
4) Call tk2dSpriteCollectionData.CreateFromTexture.

Code: [Select]
tk2dSpriteCollectionData.CreateFromTexture(
    characterTexture,
    tk2dSpriteCollectionSize.ForTk2dCamera(Camera.main),
    names,
    regions,
    anchors
);

Two more questions related to this.  Is there a packing algorithm that you suggest using (perhaps the one that tk2d uses)?  Also, how fast is tk2dSpriteCollectionData.CreateFromTexture?  Can it be done in realtime (e.g. if I swap out a red leg piece for a blue leg piece, can I refresh the atlas by calling CreateFromTexture quickly)?

9
Can you explain the basic workflow of using render textures?  I watched a few tutorials and wasn't really able to piece it together.  Are you supposed to use RenderTexture to generate the atlas and then plug it into tk2dSpriteCollectionData.CreateFromTexture?  Is there sample code available for this?

10
Hello, I am trying to create a customizable 2D character that is comprised of 30 different sprites.  Assuming that there are 10 variations of each sprite, there would be 300 sprites in total.  I also want to have multiple characters on screen at one time.  As a result, I am trying to figure out what's the best way to render a given character at runtime if I know the sprite names that need to be shown.  There are three solutions:

  • Create an atlas for each of the 10 character variations offline.  However, this would require me to load all 10 atlases if the character uses a sprite from each character variation.  This will waste memory because I am loading a lot of sprites I will never use.
  • Create an atlas for each sprite.  This would require 30 draw calls per character.  If I have 5 characters on screen, that would require 150 draw calls which is too much.
  • Since I know which sprites the character will use, I can theoretically create an atlas at runtime and use that.  This will require 1 draw call per character.

I want to attempt the last solution.  However, I am trying to figure out how to do that with TK2D.  I have been reading other threads such as this one: http://2dtoolkit.com/forum/index.php/topic,2576.15.html.

However, I have a few questions about the workflow for this works.  From what I gather, it work as follows.

  • Use Texture2D.PackTextures to pack the correct textures into an atlas.
  • Use tk2dSpriteCollectionData.CreateFromTexture to create a tk2dSpriteCollectionData.
  • Use RenderTexture to actually display the character?  I'm looked at the Unity documentation for Render Texture and am not sure how it fits into the workflow.

Can you help advise on the workflow above or suggest something else completely if it is not correct.

11
Hello, I am interested in packing 1x/2x tk2dSpriteCollections into AssetBundles.  I started reading some of the other threads on the topic, but am not entirely clear on what actually needs to be in the AssetBundle.

Here's my best guess - please correct me where I am wrong:

1. In a new project, create a tk2dSpriteCollection that uses "1x" platform setting.  Create a different tk2dSpriteCollection that uses "2x" platform setting.  Add all the appropriate sprites and commit the collection.  Is it okay to use PNG settings here?
2. Add the tk2dSpriteCollectionData component to the AssetBundle using the following code:

Code: [Select]
tk2dSpriteCollectionData data;
BuildPipeline.BuildAssetBundle(data, new Object[] { data }, path, BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.CollectDependencies);

3. Download the Asset Bundle and perform the following code for to set a sprite.

Code: [Select]
AssetBundle ab = <reference to an assetbundle>;
sprite = GetComponent<tk2dSprite>();
sprite.collection = ab.Load ("human", typeof(tk2dSpriteCollectionData)) as tk2dSpriteCollectionData;
sprite.SetSprite("mySpriteName");

12
Support / Re: Sprites Shrinking by Factor of 100 on Game Start?
« on: May 09, 2014, 05:11:20 pm »
I figured it out.  RetinaPro, a plugin I use for NGUI, was broadcasting MakePixelPerfect or something of the sort which messed up the scale.

13
Support / Particle Systems Rendering Behind All tk2dSprites
« on: May 09, 2014, 05:10:36 pm »
Hello, I have set up a scene where my camera is at z: -10, my tk2D sprites are at z: 0, and my particle system is at z: -5.  When I generate particle effects, my particles are definitely in front of the sprites in the scene view, but get rendered behind the sprites in the game view.  Why is this happening?  I am using an orthographic camera by the way.

14
Support / Sprites Shrinking by Factor of 100 on Game Start?
« on: May 08, 2014, 06:59:05 am »
Hello,

I am working with 2DToolkit, and I have set my tk2dCamera to Pixels per Meter of 100, and set it to orthographic.  I have a sprite in my scene from one tk2dCollection, and when I start the game, the scale automatically shrinks from 1 to 0.01.  On the other hand, if I have a sprite from another tk2dCollection, it does not shrink the scale automatically.  What is going on?  I tried to look in the tk2dCollection settings but my Pixels per Meter for both collections are set to 100.

Pages: [1]