I want to have a shake gesture in sprite kit, I can only do the functions in view controller .m, so how do I get the shake gesture so it works on a different scene in sprite kit? Because when I call the function from the scene in sprite the function does not get called so, how do you get the function to be called in a sprite kit scene or transfer it from the the view controller to the Sprite Kit Scene. Thanks
Asked
Active
Viewed 586 times
0
-
Please add the code for what you have already tried. – ZeMoon Jul 15 '14 at 06:06
-
Also, have a look at this: http://stackoverflow.com/questions/150446/how-do-i-detect-when-someone-shakes-an-iphone – ZeMoon Jul 15 '14 at 06:07
-
Thank You, but that does not help my situation because I know how to use the shake motion gesture but, in an SKScene the motion gesture does not work, the function never gets called but in the view controller .m it will get called and work. – user3808710 Jul 15 '14 at 20:05
-
If you are getting the data in the viewController, then you can pass this off to the SKScene and handle it from there. – ZeMoon Jul 15 '14 at 21:00
-
All this would be much easier if you post whatever you have been able to implement in this regard. – ZeMoon Jul 16 '14 at 09:24
-
Basically, you need to add a method to the subclassed scene, and call that method from the viewController which holds the scene. – ZeMoon Jul 16 '14 at 09:25
1 Answers
0
How about simply handing any motion gestures over to SKScene as in follow: -
// hand-over motion gestures to SKScene
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
SKView * skView = (SKView *)self.view;
[skView.scene motionBegan:motion withEvent:event];
}
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
SKView * skView = (SKView *)self.view;
[skView.scene motionCancelled:motion withEvent:event];
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
SKView * skView = (SKView *)self.view;
[skView.scene motionEnded:motion withEvent:event];
}

Benny Khoo
- 725
- 6
- 15