我试图在每次触摸某个区域时向下移动一个精灵节点。这是我的代码,日志显示触摸注册。我做错了什么,是否有更简单的方法来实现这一目标?
-(void)update:(CFTimeInterval)currentTime {
CGPoint currentLocation = [currentTouch locationInView:currentTouch.view];
if (currentLocation.y > 500) {
CGFloat newY = _bg.position.y - 25;
_bg.position = CGPointMake(_bg.position.x, newY);
NSLog(@"touchtouch");
}
答案 0 :(得分:0)
试试这个:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in touches) {
CGPoint currentLocation = [touch locationInNode:self];
if (currentLocation.y > 500) {
CGFloat newY = _bg.position.y - 25;
_bg.position = CGPointMake(_bg.position.x, newY);
NSLog(@"touchtouch");
}
}
}
您还可以使用SKAction
对动画进行动画处理:
SKAction *moveDown = [SKAction moveToY:newY duration:1];
[_bg runAction:moveDown];
希望这可以帮到你!