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

Pages: [1] 2
1
Thanks for the link.

I found an idea from one of your answers  here http://2dtoolkit.com/forum/index.php?topic=356.0#msg_1529  :P

So now I am doing following.

1] Keep the tk2dsprite already added to the gameobject and set the expected sprite collection. , earlier I was adding it at run time.
2] Now at run time decide upon which animation to play and set its animation library.
3] Now, on this gameobject's tk2dSprite do following :-

Code: [Select]
sprite.GetCurrentSpriteDef ().material.SetTexture ("_MainTex", Resources.Load (pathForShirt + "atlas0") as Texture);
One most important thing its doing is getting "current" sprite definitions. and that is all I wanted. Directly modifying the sprite definitions which are currently loaded in memory. It works like charm.

my only concern now is that : Whether this approach can break things ? as I am not changing the material any where but only textures.My earlier approach corrupted the sprite collection and I had to create sprite collection again. Once you confirm this I am good to go :)


2
Quote
all you really needed to do is change the textures on the material, why aren't you doing that?
I tried it, it changes the texture for a second, then change it back to the original one. I think its happening because as soon as animation is played it refers the one to which sprite collection points. For a proof I didn't play the animation and the new texture was there.

 What you think ?

Also this line

Code: [Select]
scData = tk2dSystem.LoadResourceByName<tk2dSpriteCollectionData>("Boy_Mid_Torso1_SpriteCollection");

returns null. The sprite collection is marked loadable.

3
I am able to change the sprite collection data at runtime. But the change is reflected in once I close the game and start again. So all I need is to refer the latest updated sprite collection at ru time . So I did following but it is not working, it doesnot refer to the latest sprite collection.I have marked the collection as loadable

Code: [Select]
tk2dSpriteCollectionData collectionData = animatorObject.gameObject.GetComponent<tk2dSprite> ().Collection;
SetAtlasAndMaterialAsPerClothsSelected (collectionData); // here I have updated the material and atlas as per my need
animatorObject.GetComponent<tk2dBaseSprite>().
SetSprite(tk2dSystem.LoadResourceByName<tk2dSpriteCollectionData>("Boy_Mid_Torso1_SpriteCollection"),
                                                                                                "boy_mid_jump_torso"
                                                                                               );




EDIT : I have been able to do it using following code , I had to strip away the tk2dSprite and tk2dSpriteAnimator to add it at run time : -


      
Code: [Select]
tk2dSpriteCollectionData scData = Resources.Load("Temp/Boy_Mid_Torso1_SpriteCollection",typeof(tk2dSpriteCollectionData)) as tk2dSpriteCollectionData ;


SetAtlasAndMaterialAsPerClothsSelected (scData);

part.gameObject.AddComponent<tk2dSprite>();

animatorObject = part.gameObject.AddComponent<tk2dSpriteAnimator> ();

part.gameObject.GetComponent<tk2dSprite>().SetSprite(scData,"Home_idle_torso");

EDIT 2: I just found that above way of setting the collection doesnot actually set the sprite collection. The tk2dSprite is not referencing any sprite collection when I check in inspector, but some how animation is playing. What might be wrong ?

Although it plays the animation but before playing it it throws NullReferenceException at line following function Bold Line

Code: [Select]
public void SetSprite(tk2dSpriteCollectionData newCollection, int newSpriteId) {
bool switchedCollection = false;
if (Collection != newCollection) {
collection = newCollection;
[b] collectionInst = collection.inst; [/b] // throws NullReferenceException.
_spriteId = -1; // force an update, but only when the collection has changed
switchedCollection = true;
}

spriteId = newSpriteId;

if (switchedCollection) {
UpdateMaterial();
}
}

My concern is If its not able to get the reference then how animation is playing ?

Edit 3: I just found that the sprite collection I am messing up with that is Boy_Mid_Torso1_SpriteCollection, cannot be found by the system. While setting this sprite collection for in animation editor, It keeps on Scanning the project folder forever for Rebuilding the indexes and throws error "Sprite Collection cannot be found : this is serious problem" . What went wrong ? How to fix it ?

4
Hi,

I have a sprite collection for torso of bear.This collection have frames for running of bear. Now I want to have bear in some other colored shirt say yellow. I don't want to create running frames of bear  in yellow shirt. So I am thinking of :-

1] Create a copy of the green shirt's atlas0.png, which is created inside the sprite collection data of green shirt sprite collection.
2] Create its own material.

Then at run time depending on which shirt Player selects, I will change the material and atlas in the sprite definitions.But I will be accessing sprite collection data via the tk2dSprite. Like this:-

Code: [Select]
tk2dSpriteCollectionData torso = transform.FindChild ("Torso").GetComponent<tk2dSprite> ().Collection;
I did it manually as of now, it works fine.

My question is :-

1] Is this approach can break the things, as I am not updating "Source texture GUID" ? but changing the source atlas and material directly.
2] What may be the better way of achieving what I am trying.



5
Support / Re: Crash on changing sprite collection at runtime.
« on: January 06, 2015, 05:15:05 am »
Code: [Select]
Resources.Load(BasePath.m_BasePathForCollections+"Hyderate" , typeof(tk2dSpriteCollectionData)) as tk2dSpriteCollectionData;
this line works fine and I tried printing name of collection after this line like :-

Code: [Select]
Debug.Log("----- BearAnimation.m_Collection "+BearAnimation.m_Collection.name);
it crashes here also saying :-

NullReferenceException: Object reference not set to an instance of an object

so if I try to set this sprite  collection it gives the crash as I have mentioned earlier.

PS : I am using unity 4.6.1

6
Support / Re: Crash on changing sprite collection at runtime.
« on: January 05, 2015, 12:36:31 pm »
Quote
have you tried printing out BearAnimation.m_Collection?

It won't give anything as by default its null and while loading collection to it crashes the build.

so I just tried printing the

Code: [Select]
BearAnimation.m_AnimationObject.GetComponent<tk2dBaseSprite>().Collection.name
as I am trying to change the collection of BearAnimation.m_AnimationObject and it gives name correct name.

Please let me know if I missed anything



7
Support / Crash on changing sprite collection at runtime.
« on: January 05, 2015, 09:35:26 am »
Hello,

I am trying to change the sprite collection at run time  as follows :-

Code: [Select]
BearAnimation.m_Collection = Resources.Load(BasePath.m_BasePathForCollections+"Hyderate" , typeof(tk2dSpriteCollectionData)) as tk2dSpriteCollectionData;
BearAnimation.m_AnimationObject.GetComponent<tk2dBaseSprite>().SetSprite(BearAnimation.m_Collection,1);

but if give following error :-

Object reference not found at  line

Code: [Select]
collectionInst = collection.inst;
in following function

Code: [Select]
public void SetSprite(tk2dSpriteCollectionData newCollection, int newSpriteId) {
bool switchedCollection = false;
if (Collection != newCollection) {
collection = newCollection;
collectionInst = collection.inst;
_spriteId = -1; // force an update, but only when the collection has changed
switchedCollection = true;
}

it essentially means there is no sprite collection already set , which is not true as I have attached one.


Please suggest how I can swap sprite collections at run time ?

8
Support / Re: How to add new Pant to the existing character.
« on: December 23, 2014, 07:46:49 am »
Quote
You can do it using GetPixel / SetPixel with Unity textures.

So using these function if I want to change the shirt of the character: I will read the pixels which represent the shirt  , then set the pixels of selected shirt on this existing shirt .

But how to detect , which pixels represents shirt ?
and
how to get UV coords of these pixels ?



9
Support / Re: How to add new Pant to the existing character.
« on: December 20, 2014, 05:49:42 am »
Quote
You can draw clothes on a separate sprite and draw it on top of your character sprite if you want

How to do it ?

What I was thinking is to change texture of the legs from current to the texture of pants , for all the 10 frames and then create atlas for these 10 frames to create animation and this will be done only when pant is finalized as the selection .

 Can this be done programmatically ?

10
Support / How to add new Pant to the existing character.
« on: December 18, 2014, 05:08:22 am »
I have a character with 10 frames. I have created a sprite collection for these 10 frames and using 2dtoolkits own animation I am animating it.
I understand that atlas is created for these 10 frames .
Now I want to change the appearance of the character say I want to apply new pant. How I can do it with minimal efforts, I mean do artist really need to develop another character with new pant and its 10 frames ?

11
Support / Re: Tiles Jitters when map is moved
« on: November 22, 2014, 06:11:24 pm »
Quote
There are a lot of threads in unity forums regarding this with no definitive answers.

True..have already applied which already been said.

12
Support / Re: Tiles Jitters when map is moved
« on: November 22, 2014, 02:43:46 pm »
well I did update to tk2d 2.5 but didn't help. Even setting the camera motion in multiples of 0.01 , as pixel per meter is 100. Didn't help.

It seems like a physics issue. I made Character kinematic and  now I am using a character controller which moves / jumps character without using inbuilt physics. There is enormous improvement and far less jitters. Is physics causes such problems ? How have been your experience in using physics in Unity ? Is it because there are two different updates happening in game and everything has to be in sync ?

13
Support / Re: Tiles Jitters when map is moved
« on: November 13, 2014, 05:43:23 pm »
I studied the code of TileMap demo . I changed the color of background to white from black because I was feeling like the map is jittering as the Player moves and I was right the Map actually jitters if you observe closely . Can you please confirm from your end ?

14
Support / Re: Tiles Jitters when map is moved
« on: November 12, 2014, 03:15:44 pm »
I will try you suggestion.

But sir I have a concern ,  if this is the way it should be why no one has mentioned it yet ? I am sure I am not the first person developing a platformer using unity and 2dtoolkit. I mean I searched a lot before posting but could not find anything close to what we are discussing. May be I should improve my search skills.

15
Support / Re: Tiles Jitters when map is moved
« on: November 12, 2014, 12:45:36 pm »
target is the Character I am translating left to right.

I translate it like  : transform.Translate (new Vector3 (1.5f * Time.deltaTime,0,0));

Quote
]If you're getting it with boxes your options are running low - you should try snapping to a pixel, eg. if your camera is 100 pixels per meter, make sure you move in increments of 0.01 and never anything else.

yes my pixel per meter is 100 , so how I can make sure that I move in increments of 0.01 , as I am using translate. May be I am missing something.

Pages: [1] 2