我知道這個問題之前已經被問過了,但我認爲答案可能需要更新,因爲它目前不適用於使用Xcode 8.3.3 for Mac OS的SpriteKit。看完這個post後,我意識到可以在AppDelegate中完成的事情現在應該在ViewController中完成,但它不起作用。任何人有任何建議,爲什麼這不起作用?下面是我的各種類的樣子:SpriteKit MouseMoved不能正常工作
ViewController.m
#import "ViewController.h"
#import "GameScene.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Load the SKScene from 'GameScene.sks'
GameScene *scene = (GameScene *)[SKScene nodeWithFileNamed:@"GameScene"];
// Set the scale mode to scale to fit the window
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene
[self.skView presentScene:scene];
self.skView.showsFPS = YES;
self.skView.showsNodeCount = YES;
//added in hopes that mouse moved events would be captured
[self.skView.window setAcceptsMouseMovedEvents:YES];
[self.skView.window setInitialFirstResponder:self.skView];
}
@end
GameScene.m
#import "GameScene.h"
@implementation GameScene
- (void)didMoveToView:(SKView *)view {
}
-(void) mouseMoved:(NSEvent *)event {
NSLog(@"blah");
}
-(void)update:(CFTimeInterval)currentTime {
// Called before each frame is rendered
}
@end
你沒問究竟同樣的問題在幾個星期前? –
是的。我完全忘記了這一點。無論哪種方式,沒有人發佈過答案。我將刪除舊的問題。 – 02fentym
如果你有興趣,我可以告訴你如何在Swift中做到這一點。我記得你的舊主題,因爲我在Swift中發佈了代碼,然後在意識到你在Objective-C中需要它之後將其刪除。不管你是用Objective-C還是Swift編寫它,這個概念都是一樣的。 –