Objective c SpriteKit目标c节点仅在x轴上移动

Objective c SpriteKit目标c节点仅在x轴上移动,objective-c,sprite-kit,objective-c-blocks,skspritenode,Objective C,Sprite Kit,Objective C Blocks,Skspritenode,我用SriteKit做了一个简单的游戏,球只是上下弹跳,当球落下时,你们需要把棋盘放在下面,这样球才能弹回,现在我可以把棋盘放在屏幕上的任何地方,但我想放在特定的y轴上,所以棋盘只能在x轴上移动。我的问题是:我做错了什么,我需要改变什么,所以我想怎么做就怎么做? 对不起,我的英语不好 下面是我的一段小代码: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { /* Called when a touch be

我用SriteKit做了一个简单的游戏,球只是上下弹跳,当球落下时,你们需要把棋盘放在下面,这样球才能弹回,现在我可以把棋盘放在屏幕上的任何地方,但我想放在特定的y轴上,所以棋盘只能在x轴上移动。我的问题是:我做错了什么,我需要改变什么,所以我想怎么做就怎么做? 对不起,我的英语不好

下面是我的一段小代码:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    /* Called when a touch begins */
    for (UITouch *touch in touches) {
        CGPoint location = [touch locationInNode:self];
        SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"board"];
        sprite.xScale = 0.5; 
        sprite.yScale = 0.5;
        sprite.position = location; 
        sprite.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:sprite.frame.size];  
        sprite.physicsBody.dynamic = NO;

        SKAction *delay = [SKAction waitForDuration:2];    
        SKAction *remove = [SKAction removeFromParent];      
        SKAction *actionSequence = [SKAction sequence:@[delay,remove]];      
        [sprite runAction:actionSequence];
        [self addChild:sprite];
    }
}

您需要通过y轴设置位置

CGPoint touchlocation = [touch locationInNode:self];
CGPoint location = CGPointMake(touchlocation.x,100);  //where 100 is the spot on the y axis you want to stay on

我在这里看到的是,你把一个精灵放在屏幕上,它什么都不做,然后消失了,这就是目前正在发生的事情吗?@Knight0fDragon ball在那块板上反弹,它就像乒乓球游戏,唯一的区别是你不需要用手指滑动板,只需轻轻敲击,我给你一个答案,你触摸x上的任何地方,拨片显示在触摸x位置,指定为ylocation@Knight0fDragon非常感谢,现在它工作起来就像我想要的:)