Note that there are some explanatory texts on larger screens.

plurals
  1. PONSCursor: "set" method has no effect
    primarykey
    data
    text
    <p>I am working on a Mac application with Xcode (using cocos2d), trying to configure the cursor, and the "set" method does not seem to have any effect in some cases... </p> <p>I already had a hard time to set my cursor at the launch of the application (NSTimer to set it after the application was really launched), and now I just want it to display another image when the user clicks; I use NSNotification for that, my cursor class receives the notification, then it is supposed to set the new image, then... nothing. </p> <p>Here is some code which may help:</p> <pre><code>-(void) click { CCLOG(@"Click"); NSString *path = [[NSBundle mainBundle] pathForResource:@"point_pressed" ofType:@"png"]; NSImage *cursorImage = [[[NSImage alloc] initByReferencingFile:path] autorelease]; NSCursor *cursor = [[NSCursor alloc] initWithImage:cursorImage hotSpot:[[NSCursor currentCursor] hotSpot]]; [cursor set]; } </code></pre> <p>In the initialization: </p> <pre><code> [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(updateCursor:) userInfo:nil repeats:NO]; </code></pre> <p>And the method: </p> <pre><code>-(void) updateCursor:(id)sender { CCLOG(@"Update cursor"); [[self.cursorsDict objectForKey:@"point"] set]; } </code></pre> <p>The "updateCursor" method is also called when the application becomes active, and then it works fine, the correct cursor is displayed.<br> I have tried many things, pop and push methods, "setOnMouseEnter" (although I don't use rect yet), but no result...<br> Has anyone a clue about this?</p> <p>Edit:</p> <p>Stranger, I wrote the appWake method:</p> <pre><code>-(void) appWake { int i = rand()%3; if(i==0) [[self.cursorsDict objectForKey:@"point"] set]; else if(i==1) [[self.cursorsDict objectForKey:@"point_pressed"] set]; else if(i==2) [[self.cursorsDict objectForKey:@"open"] set]; self.state = ECursorState_Point; [NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:@selector(appWake) userInfo:nil repeats:NO]; } </code></pre> <p>Which is called by a notification:</p> <pre><code>[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWake) name:EVENT_APPLICATION_DID_BECOME_ACTIVE object:nil]; </code></pre> <p>Set in the appDelegate by:</p> <pre><code>-(void) applicationDidBecomeActive:(NSNotification *)notification { [[NSNotificationCenter defaultCenter] postNotificationName:EVENT_APPLICATION_DID_BECOME_ACTIVE object:nil]; } </code></pre> <p>And when it's called by this notification, it works fine, the cursor changes randomly; but if I remove the notification in applicationDidBecomeActive and call it somewhere else in my code, then it does not do anything (although I checked that it is called)...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload