Xcodeを使用して(cocos2dを使用して)Macアプリケーションで作業していて、カーソルを構成しようとしていますが、「set」メソッドが効果を発揮しない場合があります...
アプリケーションの起動時にカーソルを設定するのにすでに苦労していました(NSTimerは、アプリケーションが実際に起動された後にカーソルを設定します)。今は、ユーザーがクリックしたときに別の画像を表示したいだけです。そのためにNSNotificationを使用します。カーソルクラスが通知を受け取り、新しい画像を設定することになっています。その後、何もしません。
これが役立つかもしれないいくつかのコードです:
-(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];
}
初期化では:
[NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(updateCursor:) userInfo:nil repeats:NO];
そして方法:
-(void) updateCursor:(id)sender
{
CCLOG(@"Update cursor");
[[self.cursorsDict objectForKey:@"point"] set];
}
「updateCursor」メソッドは、アプリケーションがアクティブになったときにも呼び出され、正常に動作すると、正しいカーソルが表示されます。
popメソッドとpushメソッド、「setOnMouseEnter」(まだrectは使用していませんが)を試しましたが、結果はありません...
これについて誰かが手がかりを持っていますか?
編集:
見知らぬ人、私はappWakeメソッドを書きました:
-(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];
}
これは通知によって呼び出されます:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWake) name:EVENT_APPLICATION_DID_BECOME_ACTIVE object:nil];
appDelegateで設定する:
-(void) applicationDidBecomeActive:(NSNotification *)notification
{
[[NSNotificationCenter defaultCenter] postNotificationName:EVENT_APPLICATION_DID_BECOME_ACTIVE object:nil];
}
そして、この通知によって呼び出されると、正常に動作し、カーソルがランダムに変化します。しかし、applicationDidBecomeActiveで通知を削除し、コード内の別の場所で呼び出すと、何も実行されません(呼び出されていることを確認しましたが)...