cursor detection within an animation
cursor detection within an animation
- Subject: cursor detection within an animation
- From: Jeff Martirano <email@hidden>
- Date: Sat, 17 Aug 2002 11:44:57 -0700
I have an animation (an image moving across the background ) being
drawn on a customview. The image is not an NSImageView, but rather an
NSImage drawn in with drawRect method. I had started to use multiple
NSImageViews but was told it was bad for performance. The animation
works fine although I don't notice any appreciable difference yet over
the NSImageView approach I had first taken. The problem I have now is
detecting when the mouse is over the moving image.
I have an NSTimer running every .05 calling a method that redraws the
whole background and image with setNeedsDisplay. In the drawRect method
that does the background and image drawing I have an "if" statement
looking to see if the mouse is within the area of the image (p1 is the
NSPoint of the image, "hit" is a BOOL that I use to trigger other
actions):
if ([[self window] mouseLocationOutsideOfEventStream].x > p1.x &&
[[self window] mouseLocationOutsideOfEventStream].x < (p1.x + [image
size].width) && [[self window] mouseLocationOutsideOfEventStream].y >
p1.y && [[self window] mouseLocationOutsideOfEventStream].y < (p1.x +
[image size].height))
{
NSLog(@"cursor is inside the image");
hit = YES;
}
This approach works, but not very well. It takes too much time for the
cursor to be detected within the area of the image and I need the
detection to happen near instantly. I have tried to increase the firing
rate of the NSTimer by decreasing the interval, but the lowest I was
able to get it to somewhat reliably fire was .03, and even then it
varied from .03 to .15.
I would like to find a way of making the cursor detection within the
image much faster. Any help would be appreciated, code examples would
be most helpful.
Thanks,
Jeff
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.