On Feb 19, 7:00 am, Zombies and Robots <caecus...@gmail.com> wrote:
> I've been trying to follow everything you guys have been talking
> about, but I must admit that after trying several ways of implementing
> what you suggest, I still haven't been able to achieve any positive
> results.  Could one of you provide some example code?  Specifically,
> I'd like to know how to go about making the main/UI thread sleep.  If
> it's applicable to my games, it would also be nice to know how to set
> up a polling model like Jon implemented.

Here's what my code looks like. On the UI thread:

public boolean onTouchEvent(MotionEvent event) {
    // Store event somewhere the game thread can see it:
    // ...

    synchronized (someObject) {
        try {
            someObject.wait(1000L);
        } catch (InterruptedException e) {
        }
    }

    return true;
}

and on the Game thread:

void myGame() {
    while (!stopping) {
        // ...

        // Get a touch event:
        synchronized (someObject) {
            someObject.notify();
        }
        Thread.yield();

        // ...
    }
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to