Help with Animating and detecting position

Discussion in 'Public Game Developers Forum' started by JuncoPartner, Feb 8, 2009.

  1. JuncoPartner

    JuncoPartner Well-Known Member

    Nov 2, 2008
    Developer, Redwind Software
    Dublin, Ireland
    Hi guys,

    I'm just working on a simple proof of concept app at the moment and having a couple of issues that I hope a more experienced dev might be able to help me with.

    Basically the gist is:
    Animate using Core Animation one object around the screen.
    Move a second object around the screen with my fingers.
    So far so good.
    Now the next thing I want to do is detect if the two objects ever meet.
    So the first thing I tried was hooking up a Timer object and firing every 0.01 and detecting whether the two objects intersect. This works fine, except as you might imagine it starts to lag like crazy!
    So changing the timer to fire every 0.2 seems to run a lot more smoothly but it doesn't now detect when the two objects meet as accurately as it should.

    So my next idea was to move the collision detection to a separate thread. Basically a simple while loop... while !collision then detect...
    OK so now the app runs perfectly smoothly except it doesn't actually detect anything. By printing logs I can see that the second thread is only ever seeing my objects at their original positions, before animation.

    I am using the presentationLayer to get the location [[topLeft.layer presentationLayer] frame] but it seems this doesn't work when I am in a second thread. I guess similar to .net background threads are not allowed interact with UI elements directly?

    Does anyone have any ideas/tips to point me in the right direction to achieve what I need?

    Thanks in advance

    P.S. I have also posted this over at MacRumors but so far haven't had any responses :(

Share This Page