Hello Guest

Author Topic: Practical 2D Toolkit C# examples?  (Read 6846 times)

2dii

  • Guest
Practical 2D Toolkit C# examples?
« on: May 19, 2013, 01:30:39 am »
Hi,
Maybe first a little on my background, I'm just a few weeks into Unity, C# & 2D Toolkit now. I've bin through a lot of tutorials and I'm seeing progress every day :)

I found there are many 2D Toolkit classes and functions, but for now I only need to use some basic 2Dtk functions. Still I've been not very successful at getting them working in my code. I might just need to read this page: http://unikronsoftware.com/2dtoolkit/doc/html/index.html  ..when it's done haha ;D
But basically I'd love to find just a few more examples on how to use them to get things up and running. Maybe something similar to this one: http://unikronsoftware.com/2dtoolkit/doc/tutorial/scripting_an_animated_sprite.html (where can I find the int clipId in this?)

I now have script attached to a game object, it creates and instantiated a new game object prefab that is  an animated clip. Like this:

Code: [Select]
using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour
{
public GameObject prefab_clip;
private tk2dAnimatedSprite anim;

// Use this for initialization
void Start ()
{
anim = GetComponent<tk2dAnimatedSprite>();
prefab_clip = Instantiate(prefab_clip, transform.position, transform.rotation) as GameObject;
}

// Update is called once per frame
void Update ()
{
if(Input.GetMouseButton(0))
{
prefab_clip.renderer.enabled = true;
}
else
{
prefab_clip.renderer.enabled = false;
}
}
}

It works fine, and I love how well the sprites are handled in the editor, but I guess it's not the way 2D Toolkit was meant to be used.
Any tips, hints, tutorials and practical examples on how to get the basic tk2D functions working in the scripts are very much appreciated.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Practical 2D Toolkit C# examples?
« Reply #1 on: May 19, 2013, 12:41:18 pm »
http://unikronsoftware.com/2dtoolkit/doc/html/annotated.html <- the script reference is the class list, I never made a specific index page.

I'm not exactly sure what you're trying to do based on your script... just enable and disable the animation based on mouse press?

2dii

  • Guest
Re: Practical 2D Toolkit C# examples?
« Reply #2 on: May 20, 2013, 02:21:57 am »
Yes, with that code I can play the clip I'd like to see on a button press and at the same time hide the clips I use for the other movements.

I was just looking for some more examples to learn from, but now I see I might just need to do a bit more studying to understand the C# classes a little better. Thanks anyway ;D

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Practical 2D Toolkit C# examples?
« Reply #3 on: May 20, 2013, 01:05:44 pm »
I think you're misunderstanding how this works. All you need is to call Play on the same animated sprite to play different clips. You don't need to hide / show, etc. I suggest going through these tutorials - you should understand at least this by the end of it.

http://unikronsoftware.com/2dtoolkit/doc/tutorial/creating_a_sprite_animation_190.html
http://unikronsoftware.com/2dtoolkit/doc/tutorial/creating_an_animated_sprite.html
http://unikronsoftware.com/2dtoolkit/doc/tutorial/scripting_an_animated_sprite.html


2dii

  • Guest
Re: Practical 2D Toolkit C# examples?
« Reply #4 on: May 20, 2013, 11:58:06 pm »
Thanks! I did use those for the setup of my 2D project. But it was still very new at that moment, I guess I just had to do it again to really let it sink in..  :D
But I've got it working now, the way the script handles the sprites saves a lot of trouble. This is good!! :)