我试着用一根手指来旋转一个精灵。老实说,我不知道该怎么做,这是spriteKit的新鲜事。有什么想法吗?
发布于 2014-10-12 11:48:13
这将使雪碧旋转到你使用动作触摸的地方。如果你想让它在拖动手指的时候旋转。您应该删除该操作并在touchesMoved:上进行计算。
-(void)didMoveToView:(SKView *)view {
sprite = [SKSpriteNode spriteNodeWithImageNamed:@"Spaceship"];
sprite.xScale = 0.5;
sprite.yScale = 0.5;
sprite.position = CGPointMake(self.frame.size.width / 2, self.frame.size.height/2);
[self addChild:sprite];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in touches) {
CGPoint location = [touch locationInNode:self];
float dY = sprite.position.y - location.y;
float dX = sprite.position.x - location.x;
float angle = atan2f(dY, dX) + 1.571f;
[sprite runAction:[SKAction rotateToAngle:angle duration:0.5 shortestUnitArc:YES]];
return;
}
}或者:(记住从touchesBegan:中删除代码)
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
for (UITouch *touch in touches) {
CGPoint location = [touch locationInNode:self];
float dY = sprite.position.y - location.y;
float dX = sprite.position.x - location.x;
float angle = (atan2f(dY, dX)) + 1.571f;
sprite.zRotation = angle;
}
}https://stackoverflow.com/questions/26318283
复制相似问题