【问题标题】:Sprite-kit action using blocks使用积木的 Sprite-kit 动作
【发布时间】:2015-04-14 00:39:44
【问题描述】:

我有什么:

  • 你点击,一个球就会移动到那个位置。

  • 屏幕在上下之间水平分割。

  • 假设球位于下侧,您无法单击下侧使其移动。您必须单击屏幕的顶部。上下翻转。

我要做什么:

  • x 坐标根本没有变化。

  • 当球到达顶部时,它会改变方向并返回而无需点击

  • 删除UITouch位置变量

  • 上下撑杆系统撑杆

    每件事都有帮助,非常感谢你。

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        /* Called when a touch begins */
        //SKAction *action = [SKAction rotateByAngle:M_PI duration:1];
        //[sprite runAction:[SKAction repeatActionForever:action]];
    
        for (UITouch *touch in touches) {
            location = [touch locationInNode:self];
        }
    
        float ballVelocity = self.frame.size.height/3.0;
        CGPoint moveDifference = CGPointMake(location.x - ball.position.x,location.y - ball.position.y);
        float distanceToMove = sqrtf(moveDifference.x * moveDifference.x +moveDifference.y * moveDifference.y);
        float moveDuration = distanceToMove / ballVelocity;
    
    
        Act_Move = [SKAction moveTo:location duration:moveDuration];
        Act_MoveDone = [SKAction runBlock:^(){
        NSLog(@"stoped");}];
        ActballMoveSeq = [SKAction sequence:@[Act_Move,Act_MoveDone]];
    
    
        if(((location.y>screenSize.height/2)&&(ball.position.y<screenSize.height/2))||((location.y<screenSize.height/2)&&(ball.position.y>screenSize.height/2))){
    
            if(canTap == true){
                [ball runAction:ActballMoveSeq withKey:@"moveBall_seq"];
            }
        }
    }
    

【问题讨论】:

  • 不确定您在寻求什么帮助。你想让你的球上升,击中顶部,然后在 x 轴上返回?
  • x 轴我不想只改变 y 轴
  • 好的,但我仍然不确定你到底在问什么。你需要更好地解释你想要做什么。如果你想让球上下移动,为什么不施加一个冲动呢?你为什么在你的问题中专门引用块?
  • 我会提出一个新问题,可能会更改我的代码,然后我会找到一种方法将它链接到你抱歉新的堆栈溢出
  • 谢谢你,我没有想到将重力设置为 0 然后应用冲动,但我如何授予你对问题的信任?

标签: ios objective-c sprite-kit skaction


【解决方案1】:

要让球向上移动一定距离并自行返回,请对您的节点使用 applyImpulse。

// modify the dy value (100) to whatever value suits your needs
[myNode.physicsBody applyImpulse:CGVectorMake(0, 100)];

只要你的节点受到重力的影响,它最终会降下来。

【讨论】:

  • ty m8 我做了一个复选标记,但直到 15 代表我才能投票
猜你喜欢
  • 2022-06-11
  • 2013-11-19
  • 1970-01-01
  • 1970-01-01
  • 2014-08-24
  • 1970-01-01
  • 1970-01-01
  • 2013-11-29
  • 2015-11-09
相关资源
最近更新 更多