当用户触摸屏幕时,从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]]];
}
我不知道如何解决这个问题。任何人都知道请帮我解决这个问题。
答案 0 :(得分:1)
如果你改变了这一点会发生什么:
projectile.physicsBody.collisionBitMask = projectileCategory | monsterCategory;
到
projectile.physicsBody.collisionBitMask = monsterCategory;