1

There is just not a lot of information out there about using GKStateMachine and I was wondering where mouse events should be handled. In Apple's "Dispenser" example, they handle the mouse click events in the main scene and I was wondering if that's where they should be handled or can each state handle its own mouse events?

My purpose for using GKStateMachine in the first place is for a MacOS SpriteKit project (Objective C) I'm working on involving the creation of a Leaderboard for a tournament. In the setup phase of the app, I have a visual list of competitors and I click on them one at a time to decide on match ups.

02fentym
  • 1,762
  • 2
  • 16
  • 29

1 Answers1

2

Mouse events will be captured by visual elements e.g. nodes in the scene or the scene itself. GKStateMachine is not a visual element so it doesn't make sense for it to handle mouse events. You could expect the mouse event captured by a visual element to trigger a state change.

Mark Brownsword
  • 2,287
  • 2
  • 14
  • 23
  • Ok, that sounds reasonable actually. And yes I agree that the mouse events would be used to trigger state changes, which is how I have it right now, I just haven't implemented `GKStateMachine` yet. Thanks. – 02fentym Jan 05 '17 at 07:41
  • What about keyDown and keyUp events? Those aren't associated with a particular visual element. In my case, I only want key events to perform an action in some states, but not others. As far as I can tell, the only way to handle it would be to use a "switch" statement in the SKScene. But that kind of defeats the point of having different GKStates. – James Hall Dec 24 '20 at 00:09
  • Kind of the same question here: I want touches to not switch states, but I capture them to e.g. modify the speed of time. I only want that to happen though if the game is in a certain state. How do I check that from the scene? Let alone delegate the tough to the state. – jeanmartin Jul 24 '21 at 15:26