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

Pages: 1 2 [3]
31
Support / Re: Load/Change texture on Sprite.
« on: February 01, 2013, 09:12:44 am »
One particular problem I was facing - imagine large (near full screen) signs which appear from time to time (eg, "new level" for example). In terms of memory use it is critical to load these only when needed, and get rid of them afterwards.

Here is an exact formula to achieve this using the "single shot" CreateFromTexture method. This explains exactly how to fully "get rid of" such an image.

Starting with the name of your PNG, say imageFileName = "sign18" if the image is sign18.png. The normal Unity command Resources.Load is used to get the PNG from disk and begin using it.

Note that CreateFromTexture creates a gameObject containing the sprite. (handyTempGameObject). Note that the code below then gets the underlying tk2dSprite (handyTempTKS) using GetComponent.

Note carefully that CreateFromTexture also creates in your scene (at root level) the actual sprite COLLECTION needed for the "one-off" sprite. You will see it in the scene at root level and you can get to it via handyTempTKS.collection.gameObject. You must remember to later also Destroy that COLLECTION as well as the sprite game object.

In the example code, I simply move the COLLECTION under the game object (ie, using .parent). This means that later, the COLLECTION will all be trashed when you simply call Destroy on the sprite game object, i.e. you won't forget to separately Destroy it.

The first time you run the code in editor, you will get a warning "you must move _ _ _ shader to a resources folder." Bring up that shader, show in finder. Make a Resources/ folder there beside it (it may exist already). COPY the shader in to that Resources folder.

   var handyTempGameObject:GameObject;
   var handyTempTKS:tk2dSprite;
   var tempTexture:Texture2D;
   tempTexture = Resources.Load( imageFileName, Texture2D );

   // now create the temporary sprite
   // the code shows how to set the size, anchor, screen-size and scale
   // note that you can use SpriteCollectionSize.ForTk2dCamera()
   // rather than SpriteCollectionSize.Explicit() if relevant to you.
   // PS remember to pop the shader in to a Resources/ folder
   // you will get a clear alert telling you which shader to move, if you forget.

   var tSize:Rect = new Rect(0, 0, tempTexture.width, tempTexture.height);
   var tAnch:Vector2 = new Vector2(tempTexture.width/2, tempTexture.height/2);

   handyTempGameObject =
      tk2dSprite.CreateFromTexture( tempTexture,
         tk2dRuntime.SpriteCollectionSize.Explicit( 1, 1536 ),
         tSize, tAnch );
   handyTempTKS = handyTempGameObject.GetComponent(tk2dSprite);
   handyTempTKS.scale = Vector3(2,2,1);

   // critical: keep track of the dynamic COLLECTION, to release it later:
   handyTempTKS.collection.transform.parent = handyTempGameObject.transform;
   
   // have an empty object called something like "holder" in the correct
   // position you want to use the large dynamic sign.
   // typically you would have eg. unity animations (perhaps a bounce, etc)
   // and anything else (scripts etc) you need on that holder.
   // put the dynamic sign in that holder
   handyTempGameObject.transform.parent = signHolder;
   handyTempGameObject.transform.localPosition = Vector3(0,0,0);


   // now use your sprite here, as needs be.
   // do whatever you want with the holder, eg,
   // slide it across the screen, blink it, whatever.
   // use your sprite here, as needs be
   // use your sprite here, as needs be


   // finally to fully unload everything from memory is this simple
   // these two lines of code:
   DestroyImmediate( handyTempGameObject );
   Resources.UnloadAsset( tempTexture );
   // since we put the dynamic collection "under" the sprite game object,
   // it is released properly.  alternately, leave it at the root level but
   // it is essential to remember to call DestroyImmediate on it also


Thanks as always to TK "ultimate gold-plated user support" !

32
Support / Re: Load/Change texture on Sprite.
« on: January 31, 2013, 12:52:10 pm »
I don't know how to get at allResourceEntries ...

(isn't that just in the Editor?)

33
Support / Re: Load/Change texture on Sprite.
« on: January 22, 2013, 02:30:45 pm »
To be clear, if you have a collection called say "Test".

In your Project panel, there will be an object called "Test".  There will be a folder called "Test Data".  inside that folder will be a number of Atlas, and also, another object called "Test".  It is the object inside the folder named Test, which you drag to the variable slot in the Inspector.

I have always wondered if there is a way to get these by NOT using the Inspector-dragging.

Something like, spriteCollectionData = .. Find in the Project/Assets .. ("Test");

Thanks if anyone knows this.

34
Releases / Re: 2D Toolkit 1.75 beta 4
« on: June 22, 2012, 03:57:13 pm »
1. loving beta 4

2. Trivial -- I don't seem to be getting "email alerts about new betas" .. something I should do?

3. You know your amazing "Setup for Javascript" system.  You know what would be a little handy: "Strip documentation and demos"  I hate that Unity packages come with the demos all mixed in.  I realise it's easy to simply select not to import them, but still.  It would be great if TK did a check and said "your installation is production ready!"  :)

4. Is it worth considering an Uninstall script ?  Why I asked:  I moved a prefab from an old project to my current project.  Somehow, it horked up tk2d.  I had to carefully remove every tk2d script/asset - and then installed this new beta.  Just something to consider.  Alternately perhaps some sort of checker function that makes sure you have everything, no dupe or old versions perphaps.  Just to consider.

Cheers on B4 !!

35
HEH!  a magic fix.

To be clear this is still a problem in 1.75 beta3, today is Sunday June 17

right ??

36
To be clear ... with the excellent 2DTK camera, physics would not work or be dramatically different, if you are using normal Unity physics .. correct?   (In short, you's have to dramatically change the value for gravity, among other things, I think.)  Since a pixel kind of becomes a meter.

Pages: 1 2 [3]