Hello Guest

Author Topic: Use tk2dUIItem or tk2dButton  (Read 8070 times)

7thsmith

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Use tk2dUIItem or tk2dButton
« on: September 08, 2014, 08:54:02 pm »
I am having a little bit of a problem and I hope this has not been discussed in another forum. 

I wanted to know if it is better to use UIItem or the tk2dButton class for a button in my game?  I am using 2 buttons to move a character either to the left or to the right.  Right now I am using UIItem and it works but there is a delay when I click on either of the buttons.  When I click either of the buttons there is a 1 second delay before the character starts moving. 

I need the player to move while a player is pressing either of the buttons but I can't get that to work with tk2dButton, it only calls my method once.

Thanks

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Use tk2dUIItem or tk2dButton
« Reply #1 on: September 08, 2014, 10:16:30 pm »
tk2dUIItem should work fine - I don't understand why theres a 1 second delay. What even are you hooking into? Have you tried debugging this?

7thsmith

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Use tk2dUIItem or tk2dButton
« Reply #2 on: September 09, 2014, 06:37:25 am »
I have my UIItems targeting my Player object and I am access a method called "MoveLeft on "On Down" and a method called "MoveLeftRelease"on "On Release".

Here is my code from my player script:
Code: [Select]
void Update ()
{

if (moveLeft)
{
transform.localPosition = new Vector3(transform.position.x + thePlayerSpeed * Time.deltaTime, transform.position.y, transform.position.z);
}
}

public void MoveLeft()
{
moveLeft = true;
}

public void MoveLeftRelease()
{
moveLeft = false;
}


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Use tk2dUIItem or tk2dButton
« Reply #3 on: September 09, 2014, 10:44:51 am »
Add a debug log to MoveLeft() - it should fire immediately when a button is pressed... Worst case it'll be lagged by 1 frame, depending on when your update happens vs tk2dUIManager.Update. I don't understand how there can be a 1 second delay here.

If you're still stuck post a repro case and I'll take a quick look.

7thsmith

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Use tk2dUIItem or tk2dButton
« Reply #4 on: September 10, 2014, 03:09:59 am »
So I have been debugging at lunch today and the delay is more .4 - .6 seconds. Most times it happens with the right button, the left button seems to work fine but I can get the right button not to have the delay.  It is crazy and I may need to move on to another part of the game for now and come back. Below are some of my "Debug.log" output.

veLeft called 8.578333
Moving Left 8.608844

Moving Left 9.208621
MoveLeftReleased called 9.208621
MoveRight called 9.60812
Moving Right 9.641507

Moving Right 10.57484
MoveLeftrelease called 10.57484
MoveLeft called 10.6417
Moving Left 10.67814

Moving Left 11.50854
MoveLeftReleased called 11.50854
MoveRight called 11.54166
Moving Right 11.57491

Moving Right 12.27498
MoveLeftrelease called 12.27498
MoveLeft called 12.34258
Moving Left 12.37466

Moving Left 13.04129
MoveLeftReleased called 13.04129
MoveRight called 13.77496
Moving Right 13.80823

Moving Right 14.74142
MoveLeftrelease called 14.74142
MoveLeft called 15.40811
Moving Left 15.4414

Moving Left 16.97791
MoveLeftReleased called 16.97791
MoveRight called 17.34202

7thsmith

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Use tk2dUIItem or tk2dButton
« Reply #5 on: September 13, 2014, 06:13:48 am »
Just a question for myself.  I am having this problem on my iphone game.  While testing on my iphone, when I click on my UIItem object there is that .5 second delay.  That delay is not happing when I test the game in Unity.  Could the delay be happening because of the iphone?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Use tk2dUIItem or tk2dButton
« Reply #6 on: September 13, 2014, 12:23:13 pm »
Nope, it should be have almost identically. I can understand a 1-2 frame latency, but not 0.5 seconds. It makes no sense. If you run the tk2dui demo, does the button start scaling immediately for you?

7thsmith

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Use tk2dUIItem or tk2dButton
« Reply #7 on: September 17, 2014, 04:55:18 am »
Thanks for the advice, the scale of the button in the UIdemo works fine for me.

7thsmith

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Use tk2dUIItem or tk2dButton
« Reply #8 on: September 17, 2014, 05:29:50 am »
I am also getting a second tk2dUIManager created in my game, what could be creating it?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Use tk2dUIItem or tk2dButton
« Reply #9 on: September 17, 2014, 12:23:17 pm »
Can you send me a repro case for this? I have no idea what is going on.

7thsmith

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Use tk2dUIItem or tk2dButton
« Reply #10 on: September 17, 2014, 06:12:44 pm »
I am going to try and work off the UIDemo tonight and re-build the buttons.

I could send you the Unity project, it is small and I am just starting to beta it.  I am using Unity 3.5 if that helps.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Use tk2dUIItem or tk2dButton
« Reply #11 on: September 18, 2014, 10:25:10 am »
Yeah that might help. Unity 3.5?? I could take a look, but I dont even have it installed any more, we're onto v5 now u know ;)