-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MouseMoved を取得できる UI #99
Labels
type: Enhancement
New feature or request
Comments
rrbox
added
type: Enhancement
New feature or request
type: Discussion
機能や利用方法などの考察をメモします
labels
Apr 8, 2023
Closed
SKNode のサンプルです。 class MouseTrackableNode: SKSpriteNode {
var isContainMouse = false
override func mouseEntered(with event: NSEvent) {
self.color = .red
}
override func mouseExited(with event: NSEvent) {
self.color = .white
}
func register(notificarionHandler: UINotificaitionHandler) {
notificarionHandler.notificationCenter.addObserver(self, selector: #selector(self.receiveMouseMoved(notification:)), name: .mouseMoved, object: nil)
}
func getEvent(from notification: Notification) -> NSEvent {
notification.userInfo!["event"] as! NSEvent
}
override func mouseMoved(with event: NSEvent) {
let pos = event.location(in: self.parent!)
if self.contains(pos) && !self.isContainMouse {
self.mouseEntered(with: event)
self.isContainMouse.toggle()
} else if !self.contains(pos) && self.isContainMouse {
self.mouseExited(with: event)
self.isContainMouse.toggle()
}
}
@objc func receiveMouseMoved(notification: Notification) {
let event = self.getEvent(from: notification)
self.mouseMoved(with: event)
}
} |
SKScene と SKView の設定サンプルです。 class View: SKView {
var sceneTrackingArea: NSTrackingArea?
func setTrackingArea() {
let scene = self.scene!
let trackingArea = NSTrackingArea(
rect: frame,
options: [.mouseMoved, .activeAlways],
owner: scene)
self.addTrackingArea(trackingArea)
self.sceneTrackingArea = trackingArea
}
override func updateTrackingAreas() {
self.setTrackingArea()
}
} class Scene: SKScene {
let notificationSystem = UINotificaitionHandler()
override func mouseMoved(with event: NSEvent) {
self.notificationSystem.mouseMoved(with: event)
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mouseMoved(with:)
を追加する #101The text was updated successfully, but these errors were encountered: