views:

345

answers:

1

In a little game I am writing I have a method Player - (void)walkToPoint:(CGPoint)point

I want this method to block, that is, it should not return before the player sprite reached the point.

I though this would be relatively simple and can be done with

NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
while(player.isMoving && [runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);

Basically, this works. The problem, however, is that mouse events that happen while the guy is moving are not processed. That is, when you click somewhere else while the character is moving, the mouseDown:(NSEvent*)ev etc. methods are not called until he reaches the position. (My idea was, that I ignore, that is, discard mouse events while the character is moving)

I also tried different runModes and [NSRunLoop mainRunLoop], but without success.

The animations are done by core animation (different thread?) and the run-loop runMode:beforeDate: is called inside the last mouseUp:(NSEvent*)ev call (problem with nested run loops?).

Does anybody have an idea how I can convince the above nested run-loop to continue sending mouse events? Another solution that would work equally well for me is to clear all current pending and unprocessed mouse events; but I have no idea how to do that either and it seems a little hacky to me?

A: 

did you already get a solution for this problem? I have the same problem!!!

gabe