Hello Guest

Author Topic: UI events clashing with main game input  (Read 4173 times)

Madrayken

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 21
    • View Profile
UI events clashing with main game input
« on: August 08, 2013, 07:06:01 pm »
Hi folks,

I have some buttons overlaid on my screen. Pressing the buttons does stuff, as does pressing the screen.
How do people make activating UI elements block screen-touches/mouse-clicks in the rest of the game?
So far, I have added code to every button click message, setting a 'blockAllInput' flag that the rest of the game checks. This still seems to allow the game's touch input for around one frame.
Any suggestions?

Madrayken

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: UI events clashing with main game input
« Reply #1 on: August 08, 2013, 08:40:40 pm »
I cleared this up myself.

1) Do all your input caching for your main game in Update() not FixedUpdate() or you'll sometimes miss events. Store them somewhere if you plan to use them in a FixedUpdate()-frequency function
2) t2dkUIManager.PressedUIItem will be set at the point where you're interacting with a UI item. If you test and find it positive, kill your stored events.
3) Ensure that the Execution Order of your script non-GUI event handler is correct, coming AFTER the t2dkUIManager.

I hope that helps people out a little bit.  :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: UI events clashing with main game input
« Reply #2 on: August 08, 2013, 08:56:54 pm »
Thanks for sharing the solution :)

nacs

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: UI events clashing with main game input
« Reply #3 on: November 08, 2013, 02:10:04 am »
Just wanted to say thanks for this.

I was also getting tk2d button presses getting passed onto the game and after searching through a few pages of results in this forum, found this post and did the t2dkUIManager.PressedUIItem check in my touch handler to fix the problem.