计算已调整大小的节点的高度

时间:2015-02-05 03:29:41

标签: ios sprite-kit

我创建了一个长按手势,让现场运行调整大小动作,但我不知道如何在调整大小后计算斑点的高度。我想要另一个sprite节点" feiji"移动一些距离,这正好是光点调整大小的高度。我试图获得点的速度和它的运行时间,以便我可以通过乘以它来计算高度。但它并没有奏效,而斐济并没有采取行动。

SKSpriteNode *spot;
NSDate *startTime;
NSTimeInterval pressTime;
SKSpriteNode *feiji = [SKSpriteNode spriteNodeWithImageNamed:@"feiji.png"];
feiji.position =CGPointMake(100,120);
[self addChild:feiji];

UILongPressGestureRecognizer *longGus = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longGus:)];
longGus.minimumPressDuration=0.1;
[[self view]addGestureRecognizer:longGus];


-(void)longGus:(UILongPressGestureRecognizer*)gesture
{
    
    if (UIGestureRecognizerStateBegan==gesture.state) {
        [self stickAction];
        startTime = [NSDate date];
    }
    
    if (UIGestureRecognizerStateChanged==gesture.state) {
        [self stickAction];
    }
    

   if (UIGestureRecognizerStateEnded==gesture.state) {
        [spot removeAllActions];

        pressTime  = -[startTime timeIntervalSinceNow];

        SKAction *down = [SKAction rotateByAngle:-M_PI/2 duration:0.5];
        [spot runAction:down completion:^{
            [self feijiMove];
        }];

  }

-(void)feijiMove { SKAction *move = [SKAction moveByX:(10/self.size.width) * pressTime y:0 duration:2]; [feiji runAction:move]; }

-(void)stickAction { spot = [SKSpriteNode spriteNodeWithColor:[UIColor blackColor] size:CGSizeMake(5, 5)]; spot.position = CGPointMake(100, 100); spot.anchorPoint = CGPointMake(0, 0);

SKAction *resize = [SKAction resizeByWidth:0 height:self.size.width duration:10]; [spot runAction:resize]; [self addChild:spot]; }

0 个答案:

没有答案