1
我是新來的目標c,所以還是非常瞭解繩索。我有一款遊戲,使用TheSneakyNwawhal提供的代碼在屏幕上製作虛擬遊戲杆。iOS SpriteKit虛擬操縱桿之外的觸摸會干擾操縱桿
https://github.com/TheSneakyNarwhal/SpriteKit-Joystick
我已經進口的混帳提供的文件,並將以下是相關的操縱桿實現的代碼:
-(Joystick *)newJoystickNode {
SKSpriteNode *jsThumb = [SKSpriteNode spriteNodeWithImageNamed:@"joystick"];
SKSpriteNode *jsBackdrop = [SKSpriteNode spriteNodeWithImageNamed:@"dpad"];
Joystick *joystick = [Joystick joystickWithThumb:jsThumb andBackdrop:jsBackdrop];
joystick.position = CGPointMake(jsThumb.size.width, jsThumb.size.width);
joystick.name = @"playerJoystick";
//[joystick setScale:0.8];
return joystick;
}
-(void)joystickMovement
{
Joystick *joystick = (Joystick*)[self childNodeWithName:@"playerJoystick"];
SKSpriteNode *player = (SKSpriteNode*)[self childNodeWithName:@"hero"];
if ((joystick.velocity.x != 0 || joystick.velocity.y != 0) && (self.speed == 1))
{
player.position = CGPointMake(player.position.x + .1 *joystick.velocity.x, player.position.y + .1 * joystick.velocity.y);
}
}
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
CADisplayLink *velocityTick = [CADisplayLink displayLinkWithTarget:self selector:@selector(joystickMovement)];
[velocityTick addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
[self addChild:[self newJoystickNode]];
[self addChild:[self newFireButtonNode]];
}
return self;
}
這個操縱桿移動屏幕上的字符和正常工作。我遵循上述git提供的說明。操縱桿放置在屏幕的左下角。問題在於,如果我用操縱桿移動角色並觸摸屏幕上的任何其他位置,可能會干擾操縱桿並將其拉向右側。
有沒有人使用這個實現的spriteKit操縱桿,並有這個問題?或者有人知道爲什麼會發生這種情況嗎?