当用户触摸屏幕时,从 y 轴中间创建 SKSpriteNode 图像,x 轴为零。SKSpriteNode 图像到达触摸位置。它工作正常。当用户连续多次触摸时,创建了多个 SKSpriteNode 图像但多个 SKSpriteNode 图像相互碰撞,然后除了第一个图像之外,角度发生了变化。我需要图像一个接一个地移动而不改变角度。
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch * touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKSpriteNode * projectile = [SKSpriteNode spriteNodeWithImageNamed:@"Arrow_Ballon"];
projectile.position = self.player.position;
projectile.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:projectile.frame.size];
projectile.physicsBody.categoryBitMask = projectileCategory;
projectile.physicsBody.contactTestBitMask = monsterCategory;
projectile.physicsBody.collisionBitMask = projectileCategory | monsterCategory;
projectile.physicsBody.usesPreciseCollisionDetection = YES;
[self runAction:[SKAction playSoundFileNamed:@"arrow.wav" waitForCompletion:NO]];
CGPoint offset = rwSub(location, projectile.position);
if (offset.x <= 0) return;
[self addChild:projectile];
CGPoint direction = rwNormalize(offset);
CGPoint shootAmount = rwMult(direction, 1000);
CGPoint realDest = rwAdd(shootAmount, projectile.position);
float angle = atan2f (location.y - projectile.position.y, location.x - projectile.position.x) ;
float velocity = 500.0/1.0;
float realMoveDuration = self.size.width / velocity;
SKAction * actionangle = [SKAction rotateByAngle:angle duration:0.0];
SKAction * actionMove = [SKAction moveTo:realDest duration:realMoveDuration];
SKAction * actionMoveDone = [SKAction removeFromParent];
[projectile runAction:[SKAction sequence:@[actionangle,actionMove,actionMoveDone]]];
}
我不知道如何解决这个问题。有人知道请帮我解决这个问题。