derrick56007 / SpriteKit-Joystick

Joystick class for Sprite Kit
32 stars 7 forks source link

Joystick touch issue #1

Closed RAAnderson closed 10 years ago

RAAnderson commented 10 years ago

I added the joystick to my Spritekit game and I am seeing some odd behavior related to touch. Currently if I move the joystick and hold it down in one direction. Then touch anywhere on the screen in the opposite direction the joystick sporadically jumps toward my other touch in the opposite direction and then goes back to normal.

This causes my character to lung whenever the joystick flips to the opposite side.

Has anyone else seen this behavior or have a guess as to what is causing it?

derrick56007 commented 10 years ago

Have you enabled multi touch on your view?

RAAnderson commented 10 years ago

I added self.view.multipleTouchEnabled = YES, but it didn't change the problem.

I am creating the joystick in my scene's -(id)initWithSize:(CGSize)size method. Do you see anything wrong with the way I'm creating the joystick? After debugging the joystick class with breakpoints I noticed that the self.frame.size.width & height are always zero in the class. My guess is that this shouldn't be the case.

    SKSpriteNode *jsThumb = [SKSpriteNode spriteNodeWithImageNamed:@"joystick"];
    SKSpriteNode *jsBackdrop = [SKSpriteNode spriteNodeWithImageNamed:@"dpad"];
    jsThumb.size = CGSizeMake(25, 25);
    jsBackdrop.size = CGSizeMake(55, 55);
    self.joystick = [Joystick joystickWithThumb:jsThumb andBackdrop:jsBackdrop];
    self.joystick.position = CGPointMake(size.height * 0.06, size.width * 0.7);
    [self addChild:self.joystick];
    self.joystick.zPosition = 100;

    self.velocityTick = [CADisplayLink displayLinkWithTarget:self selector:@selector(joystickMovement)];
    [self.velocityTick addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
derrick56007 commented 10 years ago

https://github.com/TheSneakyNarwhal/SpriteKit-Joystick/commit/2631e00bbdf609a83fe5328818cebce36f409582

RAAnderson commented 10 years ago

Thanks for the update! It works perfect.