Forums

Android Input problem - need to clear queue?
Last Post 01 Jan 2016 07:24 PM by Arek Kaźmierowski. 2 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Arek KaźmierowskiUser is Offline
New Member
New Member
Posts:63


--
01 Jan 2016 05:39 PM
    First of all, Hello and Happy New Year to everyone!

    Then, on to the problem

    I have a problem with touch input on Android. I'm using input in my game normally when UI is not shown - in this case I don't call Update and Draw methods on uiRoot. If menu is enabled (by three fingers touch), I draw the menu in the Draw(), and call this in Update, so the menu works:

                    // update UI
                    uiRoot.UpdateInput(gameTime.ElapsedGameTime.TotalMilliseconds);
                    uiRoot.UpdateLayout(gameTime.ElapsedGameTime.TotalMilliseconds);
    


    I also make extra effort to make sure, that showing the menu (and updating it for the first time) happens after the user gets all fingers out of the device. So he first needs to touch screen with three fingers, then remove all of them, and then the menu is enabled.

    But still, very often after the menu is shown, EmptyKeys seems to be getting some input although the screen is not touched. It looks like it collected all the touch events which happened when the menu was not shown (user was gaming), and now executes them, but instead of "clicking" elements it focuses them. So for several seconds it changes focus of different elements and the menu is not responsive.

    Do I need to clear some input buffer before updating the menu, or am I doing something else in the wrong way?
    Filip DušekUser is Offline
    Advanced Member
    Advanced Member
    Posts:676


    --
    01 Jan 2016 06:22 PM
    There is not any input buffer for touch events in EK UI. All code is behind UpdateInput method so if you don't call it, input is not processed. That's said I'm not sure if MonoGame (if you are using MonoGame/CocosSharp) has some kind of cache behind in Android implementation. You can try call MonoGame TouchPanel.ReadGesture() and TouchPanel.GetState() right before enabling menu.

    Let me know if that helps
    Arek KaźmierowskiUser is Offline
    New Member
    New Member
    Posts:63


    --
    01 Jan 2016 07:24 PM
    Ok I solved it different. It seems the code
                    // update UI
                    uiRoot.UpdateInput(gameTime.ElapsedGameTime.TotalMilliseconds);
                    uiRoot.UpdateLayout(gameTime.ElapsedGameTime.TotalMilliseconds);
    

    has to be called always, even if menu is not needed. So I call it always now, but have the root grid of uiRoot invisible if menu is needed, so the input does nothing then. And it seems the problem is gone. It was somewhat random - not happening always, so I will test more, but it looks like it solved. Wondering a little bit if it affects any performance, but I will come to profiling later..

    So the rule seems to be: update the menu every frame.
    You are not authorized to post a reply.