I figure you are running a thread that does all the processing as not to block the UI thread. If so, one of the ways I've been doing it is to add something like...
public static LinkedList<MotionEvent> uiEvents; ... to a helper object and then check the length of it every time through the processing loop. You can either call length() on this or you can keep up with the count yourself which might be a bit faster. In whatever view you are catching touches, just insert the MotionEvent into this list. This should leave the UI thread clear and let the processing thread get the touches as time allows. Once I process the first event, I remove the event from the list and continue. I tend to only process one per frame so I don't cause hitching in the movement. If you are running about 30 fps, most people won't be able to touch faster than the ~33ms they have between frames anyways. I use a LinkedList so it keeps the touches in the order I insert them so I don't have to worry about out of order touches. Just one idea, someone else may have a more effective one, but hope that helps. Steven Studio LFP http://www.studio-lfp.com On Sunday, October 23, 2011 11:42:50 PM UTC-5, Peter Webb wrote: > > I don't even know if this is an Android question or a Java question. > > I am developing a simple game using Lunarlander as a starting point. > > Input is through OnTouch events. This changes the game's state - eg a > touch event may cause some gameplay object to be instantiated. > Obviously I don't want this to occur in the middle of processing. > > How do I best synchronise the OnTouch events with the main game loop? > In other environments I have used an "atomic" event (such as creating > a dummy file) as a semaphore to work out when game objects can be > safely read and written. What should I do in Android? -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

