Ios 改变射击方向
我做了一个游戏,现在我不知道如何在你点击的地方射击,而不是直接向前Ios 改变射击方向,ios,objective-c,sprite-kit,Ios,Objective C,Sprite Kit,我做了一个游戏,现在我不知道如何在你点击的地方射击,而不是直接向前 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { /* Called when a touch begins */ //1 SKSpriteNode *shipLaser = [_shipLasers objectAtIndex:_nextShipLaser]; _nextShipLaser++; if (_nextShipLaser >
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */
//1
SKSpriteNode *shipLaser = [_shipLasers objectAtIndex:_nextShipLaser];
_nextShipLaser++;
if (_nextShipLaser >= _shipLasers.count) {
_nextShipLaser = 0;
}
//2
shipLaser.position = CGPointMake(_ship.position.x+shipLaser.size.width/2,_ship.position.y+0);
shipLaser.hidden = NO;
[shipLaser removeAllActions];
//3
CGPoint location = CGPointMake(self.frame.size.width, _ship.position.y);
SKAction *laserMoveAction = [SKAction moveTo:location duration:0.5];
//4
SKAction *laserDoneAction = [SKAction runBlock:(dispatch_block_t)^() {
//NSLog(@"Animation Completed");
shipLaser.hidden = YES;
}];
//5
SKAction *moveLaserActionWithDone = [SKAction sequence:@[laserMoveAction,laserDoneAction]];
//6
[shipLaser runAction:moveLaserActionWithDone withKey:@"laserFired"];
你要做的是在你的视野中找到触摸的位置。所以你需要把这个加入到你的touchesBegind方法中
for(UITouch *t in touches) {
CGPoint point = [t locationInView:<view>];
// for use in Sprite Kit
CGPoint point = [t locationInNode:<node>];
// make the x position of the object being shot
// equal to the point location
}
for(触摸屏中的UITouch*t){
CGPoint point=[t locationInView:];
//用于雪碧套件
CGPoint point=[t locationInNode:];
//使正在拍摄的对象处于x位置
//等于点的位置
}
希望这对你有所帮助,你想做的就是在你的视野中找到触摸的位置。所以你需要把这个加入到你的touchesBegind方法中
for(UITouch *t in touches) {
CGPoint point = [t locationInView:<view>];
// for use in Sprite Kit
CGPoint point = [t locationInNode:<node>];
// make the x position of the object being shot
// equal to the point location
}
for(触摸屏中的UITouch*t){
CGPoint point=[t locationInView:];
//用于雪碧套件
CGPoint point=[t locationInNode:];
//使正在拍摄的对象处于x位置
//等于点的位置
}
希望对您有所帮助您所需要的只是替换这一行
CGPoint location = CGPointMake(self.frame.size.width, _ship.position.y);
由此
CGPoint location = [[touches anyObject] locationInNode:self];
您只需要替换这一行
CGPoint location = CGPointMake(self.frame.size.width, _ship.position.y);
由此
CGPoint location = [[touches anyObject] locationInNode:self];
感谢您的回复,但上面说“point”是一个未使用的名称variable@user3053675他在告诉你如何进入接触点。现在,您必须将其合并到代码中。也许在第3项调整y位置?感谢您的回复,但它说“点”是一个未使用的位置variable@user3053675他在告诉你如何进入接触点。现在,您必须将其合并到代码中。也许调整项目3的y位置?