changes to allowsCameraControl (swift 4)? - ios

I have a simple SCNScene with an object placed in the center (for example, a cube). BEFORE the latest update to Swift 4, I enabled allowsCameraControl and the user could then rotate and manipulate (zoom in/out) the cube. Now, (Swift 4, iOS 11) with the exact same code, when the user manipulates the cube, SOMETIMES the direction you swipe your finger matches the direction the cube moves, while other times, the direction you move your finger causes the cube to move the opposite direction! It is NOT something that is always backwards or always correct, it can change as quickly as swiping one direction (correct cube movement), raising your finger, going back and trying to continue the same motion, but now the second swipe makes it rotate back the wrong way!
It almost seems like it's trying to use some specific point in the scene as a 'reference' of some kind. Like if that point is on the front of the object, a swipe left makes it move left. But if that point gets moved to the 'back' of the object, the next swipe left still moves the POINT left, but because it's in the 'back', moving left translates into the front of the object moving right. (with the same thing for up and down!)

Related

Swipe gesture iOS swift

Im building an app that needs to detect a swipe gesture, the detector needs to recognize a swipe in any direction (not only Up, Down, Left, Right), the swipe can be in any direction for example somewhere around up and left.
The app features a ball in the middle of the screen, when the user swipes(flings) in any direction the the ball should shoot in that direction, so if the user shoots to a corner the ball should go to the corner of the screen. I don't want to use Unity or any engine, can anyone help me with the code for swift (not swiftUI)? Thank you in advance!

iOS Spritekit Scrolling Menu

I am implementing a horizontal scrolling menu for a SpriteKit game and have become stuck as to how to go about this. My strategy was originally to add all of my menu items to the scene and just pan the camera horizontally according to swipes.
The problem with this is that the menu is revolving/circular (last item links to the first, etc) so even if I repeated the menu items infinitely, after swiping constantly one direction, I imagine a coordinate limit would be reached and the app would crash.
My next solution is to add one menu item in my camera view, one to the left, and one to the right. Then upon swiping the correct item would move into my camera view via SKAction and the original item would move away. I would then removechild the farthest node from the camera, and add the next item to the scene in the direction toward which I swiped. This way my x range (in points) would only be -displayWidth to displayWidth. The problem with this is that I would need to animate all of the menu items at the same time, and as they are separate nodes I have not seen a way to synchronize their animation.
Also I need to check the position of elements on the menu items and change their shaders when they reach the border of the screen. SKActions seem to block the SKScene update method so I am ideally trying to avoid SKActions.
Is there any viable strategy that I am missing here?
Since this is only a menu, it is ok to be a little inefficient.
What you do is have your menu cloned 2 times (so you have a total of 3). You place one of the clones to the left, and one to the right.
You then add all 3 of these into a parent SKNode. You should now have one SKNode with the 3 menu items in a long string. Make sure your anchor point is (0.5,0.5)
You then run the animation to pan left or right on the parent SKNode, with the condition that whenever you pass the edge of your original main menu, you jump in the opposite direction the width of the menu.
So let's say our menu is 400 (-199,200) points wide, and our screen is 300 points wide (-149,150). Once the parent point -200 (menu point 200 or right side of menu) aligns with screen point -150, you move the parent point to 200 (so menu point is -200 or left side of menu).
Since you are moving the parent node, all the clones will follow suit, and you only need to run 1 action.
I recommend using UIKit to create such a menu instead of SpriteKit. UICollectionView should be good for such a task.

How to tie together gestures and animation

I'm as beginner as you can get when it comes to iOS animation.
I know you can do fixed (non-gesture-controlled) animations, where you animate a property of a view over a fixed period of time. This however is entirely different than using a gesture to control the animation.
You know how you fold a sheet of 8x11 paper to put it in an envelope and mail it... you fold it in thirds. Well basically, my boss wants an interface such that 2/3rds of it is shown on the screen at a time, and the other third is slid on/off screen with a gesture. So basically, the screen would show either thirds 1 and 2, or thirds 2 and 3 depending on whether you swipe left or right.
Now this also means doing things like snapping/rubberbanding, bouncing, acceleration/deceleration, sticky. I have no clue where to even start to do something like this. I'm assuming those types of motions are not already built into any of the iOS framework and if you want snapping/rubberbanding, bouncing, acceleration/deceleration, you'd have to program that entirely from scratch.
Like how would a view know my artificial snap/bounce points are, and sticky behavior, such that you remove your finger from the screen before an arbitrary position is reached, and the view bounces back to it's previous position.
Where would you suggest I start on researching how to drive animations with gestures?
I suggest you take a look at Core Animation. You can do some really complex animations including accelerations, deceleration, bounce and others.
You could easily create a UIPanGestureRecognizer to track when someone has dragged their finger across the screen. Attach an action wasDragged to your gestureRecognizer
From the documentation:
A panning gesture is continuous. It begins (UIGestureRecognizerStateBegan) when the minimum number of fingers allowed (minimumNumberOfTouches) has moved enough to be considered a pan. It changes (UIGestureRecognizerStateChanged) when a finger moves while at least the minimum number of fingers are pressed down. It ends (UIGestureRecognizerStateEnded) when all fingers are lifted.
In wasDragged check what state the gestureRecognizer is in. If state is UIGestureRecognizerStateChanged, then you can adjust the size or position of your UIView so that it appears like you are dragging it out. If state is UIGestureRecognizerStateEnded, check whether the point at which the gesture ended is greater than your threshold point (e.g. halfway across the screen). If it isn't, then snap the view back using an animation, if it is then snap the view into where you want it.
Hope this makes sense.

Using two gestureRecognizers continuously without break

In my app, i have to implement two UIswipegesturerecognizers (left and right) one after another without removing the finger from screen.
What i have right now is user needs to swipe left and then swipe to right with removing finger .
Is there any idea how i can achieve this without removing my finger.
Thanks,
Use the UIPanGestureRecognizer and track the .x value and do the math yourself to figure out if the finger has gone far enough left from the origin (store the origin as a variable) and then far enough right from the origin.
Additionally you could just use UITouchesMoved and get the .x value of the touch.

mouse jittering in the middle of screen in XNA

When I make the mouse visible, it jitters in the middle of screen. Does anyone know what the problem might be? thanks.
update:
I can't move the mouse.. it just stays at the same point
Are you setting the mouse position anywhere in your code?
This sounds like the result of an implementation of some "free look" code that sets the mouse position to the centre of the window each frame (so it can read how far it travels and then move it back, to allow for continuous movement without hitting the edge).

Resources