在节点中使用精灵套件问题进行游戏开发?
Posted
技术标签:
【中文标题】在节点中使用精灵套件问题进行游戏开发?【英文标题】:Game development using sprite kit issues in nodes? 【发布时间】:2013-11-08 11:17:46 【问题描述】:当用户触摸屏幕时,从 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]]];
我不知道如何解决这个问题。有人知道请帮我解决这个问题。
【问题讨论】:
【参考方案1】:如果你改变这个会发生什么:
projectile.physicsBody.collisionBitMask = projectileCategory | monsterCategory;
到
projectile.physicsBody.collisionBitMask = monsterCategory;
【讨论】:
以上是关于在节点中使用精灵套件问题进行游戏开发?的主要内容,如果未能解决你的问题,请参考以下文章