2D Toolkit Forum
2D Toolkit => Support => Topic started by: 7thsmith 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
-
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?
-
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:
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;
}
-
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.
-
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
-
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?
-
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?
-
Thanks for the advice, the scale of the button in the UIdemo works fine for me.
-
I am also getting a second tk2dUIManager created in my game, what could be creating it?
-
Can you send me a repro case for this? I have no idea what is going on.
-
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.
-
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 ;)