Hello Guest

Author Topic: Recently got 2D Toolkit, little lost  (Read 5748 times)

Pani

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 29
    • View Profile
Recently got 2D Toolkit, little lost
« on: March 14, 2013, 10:43:46 am »
I've gone through the docs but they don't really explain what the purpose of some functions are, so hopefully someone here can help me with these questions;

1. What is the purpose of animationCompleteDelegate/HitCompleteDelegate? How should it be used? I see it being used in http://www.unikronsoftware.com/2dtoolkit/doc/tutorial/scripting_an_animated_sprite.html but I don't understand what for. Why is it being used for KeyCode.A and not for D or W (which are being set to null)?
2. Is there a way to specifically tell a sprite the direction to flip it in? e.g. FlipX() will flip it in the opposite direction it's in at that moment, but what if I want to specifically say FlipX(0) (left) or FlipX(1) (right) and if it's already flipped in that position it will simply do nothing. Is this possible?
3. Is there a way to repeat a sprite? Say I have a ground sprite. Rather than duplicating it over and over again for my ground, is there a way to simply repeat it in X or Y direction? I'd have thought scale would do this but unfortunately it stretches rather than repeats.

Thanks.
« Last Edit: March 14, 2013, 10:46:03 am by Pani »

dotty

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 65
    • View Profile
Re: Recently got 2D Toolkit, little lost
« Reply #1 on: March 14, 2013, 01:51:46 pm »
animationCompleteDelegate is used to define which method to run once an animation has been completed. In the linked example you can see that animationCompleteDelegate = HitCompleteDelegate and there's a method called HitCompleteDelegate().

As for animationCompleteDelegate = null, that's being set to null so that nothing gets called when the animation gets completed.

As for the FlipX() / FlipY(), you can just grab the scale of the sprite to determine which way it's current direction. By default the scale is (1,1,1), however when it's flipped on it's X (using FlipX()), the scale becomes (-1,1,1). (See http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,1268.msg6074.html#msg6074).

As for the repeating sprite, that's being worked on. If you're a paid customer, the latest beta has this function (see http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,1284.0.html).
« Last Edit: March 14, 2013, 01:56:05 pm by dotty »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Recently got 2D Toolkit, little lost
« Reply #2 on: March 14, 2013, 09:04:21 pm »
A quick note: the repeating sprite isn't meant to be animated (i.e. the dimensions changed) at runtime. It will allocate memory, and it isn't particularly fast.

Pani

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Recently got 2D Toolkit, little lost
« Reply #3 on: March 15, 2013, 10:16:47 am »
Thanks for your help, that answered my question.

Pani

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Recently got 2D Toolkit, little lost
« Reply #4 on: March 16, 2013, 12:50:20 pm »
Two more questions rather than making another thread:

1. Is there a way to have a sprite not shrink/stretch to fit? I have some sprites for my GUI for example, two of which is a filled health bar and an empty healthbar. I want to simply trim the filled health bar based on the player's health which I'm doing right now by reducing the scale, but the sprite is also shrinking to fit the new size.
2. Is there a way to clamp a sprites position to a tk2dcamera's local space? Say I have a healthbar sprite, and I have the camera following the player. The healthbar will not camera the screen. How do I make it follow the screen and keep its position in local space? Should I use the same technique as the default cameras where you set up two (one for the GUI and the other for the actual game) or does 2D Toolkit have something specific for this?
« Last Edit: March 16, 2013, 04:21:51 pm by Pani »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Recently got 2D Toolkit, little lost
« Reply #5 on: March 16, 2013, 05:54:16 pm »
1. Use the clipped sprite.
2. Either create a second camera, or attach the GUI as a child of the camera. That way it'll follow the camera and always be positioned relative to it. Creating a second camera creates a more "stable" solution, you may find with attaching the GUI that some things may start jittering a bit when your camera is far away from the origin.