touchesbegan

Move two paddles at same time in SpriteKit + Swift

二次信任 提交于 2019-12-24 13:35:37
问题 I am making a simple Pong game using SpriteKit + Swift. It is a multiplayer game, so I want two people to be able to move the two paddles. I want to be able to move the paddles at the same time. When I run the code below, which is the touchesBegan function, I am only able to move each paddle when one finger is pressing the display. When I try to touch another paddle, while my finger is already on the screen, it does not respond. let touch = touches.first as UITouch? let touchLocation = touch?

Confusing reversed touch event in Swift

天大地大妈咪最大 提交于 2019-12-24 00:57:50
问题 In my function override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){ for touch in touches{ let touchLocation = touch.location(in: self.view) print("X: \(touchLocation.x) Y: \(touchLocation.y)") } } I get reversed Y value. If I click at the top I get ~0 value and if I click at the bottom I get high value. This makes my sprite im moving move in the wrong Y direction. However if I remove '.view' in self.view it works as it should. Does anyone know why it's reversed when I

Iphone Textview does not invoke TouchesBegan

∥☆過路亽.° 提交于 2019-12-23 20:07:25
问题 I have a Textfield which hides the keyboard when I touch somewhere else on the screen (through my TouchesBegan function and resign...blah). But when I touch a Textview the TouchesBegan does not get invoked and the keyboard doesn't hide! Is there any way to invoke TouchesBegan in order to hide the keyboard? 回答1: There is also a easy way to hide the keyboard on touchesBegan: when you are using UITextView to enter the data. Step 1. Be sure that you have extended Textviewdelegate while class

swift - Jump only when landed

江枫思渺然 提交于 2019-12-23 15:37:53
问题 I'm looking to restrict my character (cat), to only jump when it's either on the ground (dummy SKNode), or when on the tree (treeP SKNode). Currently I don't have any restrictions to touchesBegan and as a result the cat is able to fly through the air if the user clicks in quick succession, whilst this could be useful in other games it's not welcome here. If anyone could help me I'd be really happy. What i would like to do but have no experience would be to enable a click (jump), if the cat

SKSpriteNode erratic swipe?

落爺英雄遲暮 提交于 2019-12-22 12:39:43
问题 I have created the following sprite kit node : SKSpriteNode *megadeth; megadeth = [SKSpriteNode spriteNodeWithImageNamed:@"megadeth_rocks.png"]; megadeth.name = @"awesome"; and added the swipe gesture as follows: -(void)didMoveToView:(SKView *)view{ UISwipeGestureRecognizer *recognizerUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeUp:)]; recognizerUp.direction = UISwipeGestureRecognizerDirectionUp; [[self view] addGestureRecognizer:recognizerUp];

viewDidLayoutSubviews called after touchesBegan - again and again

耗尽温柔 提交于 2019-12-22 11:24:57
问题 In an iPhone word game I have an UIScrollView (holding UIImageView ) and 7 draggable custom UIView s placed initially at the bottom (and outside the scroll view): In the single ViewController.m I have overwritten viewDidLayoutSubviews so that it always sets the zoomScale of the scroll view - to have the UIImageView fill exactly 100% of the screen width. This works well - for portrait and landscape modes. And when the app is just started: My problem is however, when I first pinch/zoom/double

In SpriteKit does touchesBegan run in the same thread as the SKScene update method?

廉价感情. 提交于 2019-12-22 05:04:40
问题 In the Apple documentation here Advanced Scene Processing it describes the update method and how a scene is rendered, but it does not mention when input is processed. It is not clear if this is in in the same thread as the rendering loop, or whether it is concurrent with it. If I have an object that I update from both the SKScene update method and the touchesBegan method (in this case of a SKSpriteNode ) do I have to worry about synchronising the two accesses to my object? 回答1: So after a few

TouchesBegan delay on left hand side of the display

我是研究僧i 提交于 2019-12-22 04:44:07
问题 On iPhone's with 3D touch enabled, there is a feature where long pressing the left hand side of the screen with enough force opens lets you change which app is active. Because of this, when a non-moving touch happens on the left hand side of the screen, the touch event is delayed for a second or two until the iPhone verifies that the user is not trying to switch tasks and is interacting with the app. This is a major problem when developing a game with SpriteKit, as these touches are delayed

How to get current touch point and previous touch point in UIPanGestureRecognizer method?

浪子不回头ぞ 提交于 2019-12-21 04:04:45
问题 I am new to iOS, I am using UIPanGestureRecognizer in my project. In which I have a requirement to get current touch point and previous touch point when I am dragging the view. I am struggling to get these two points. If I use touchesBegan method Instead of using UIPanGestureRecognizer , I could get these two points by the following code: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ CGPoint touchPoint = [[touches anyObject] locationInView:self]; CGPoint previous=[[touches

Stretchy UIBezierPath line?

旧时模样 提交于 2019-12-21 02:54:39
问题 I want to draw a straight line with my finger that automatically sizes based upon how far away I am from the point of origin. So if I touch the screen in the middle and slide my finger out a line appears to 'stretch' and pivot around the point of orgin as my finger moves on the screen. WHhen I lift my finger. The Destination Point should finalize and create a line. I can drag my finger across the screen and 'Draw' on the screen but that's not what I am wanting to do. I thought UIBeizerPath