I'm trying to create an animation where you touch and drag your finger across the screen and colored boxes change size based on your position. Imagine this as a color picker. Here's a gif of the idea. I did this in Corona using a touch event and enterFrame. I can't seem to wrap my head around how to create the same effect in Cocoa Touch.
Where to start with this? I can't seem to find an enterFrame equivalent in Cocoa Touch unless I go with SpriteKit. I'm not making a game, so SpriteKit seems like overkill.
I put a simple animation code on github : https://github.com/MehdiSv/SimpleAnimationColorsPicker
I used a UILongPressGestureRecognizer, and made a CGAffineTransformMakeScale depending on the distance between the touch and each view.
Here is a little preview :
Related
So I have this project that I took from somebody else and they have implemented this OneFingerRotationGestureRecognizer (https://github.com/melle/OneFingerRotationGestureDemo/blob/master/OneFingerRotationGestureDemo/OneFingerRotationGestureRecognizer.m) for a circular slider. Additionally, they have added a UITapGestureRecognizer on top of that, so you could tap a value within that circular slider and the value would jump to that specific one. Now the problem is, when I drag that thing just a very small amount (imagine putting your thumb onto the control and tilting left/right), then the UITapGestureRecognizer also fires! And this is a problem, because I want to be able to grab the circular slider wherever I want (there is no handle or something). And when I only drag it a little, then the value just jumps to that spot where I did that small dragging. Somehow I need to cancel that tap gesture as soon as that OneFingerRotationGestureRecognizer started registering touches. I tried what is described here: https://developer.apple.com/documentation/uikit/touches_presses_and_gestures/coordinating_multiple_gesture_recognizers/preferring_one_gesture_over_another?language=objc but didn't have any success with that :-(.
What can I do? I'm afraid the solution is so simple that I just don't see it.
I'm trying to make a card game app (with swift 4) like a Solitaire Card Game.
So I have to use Drag and Drop to each Card UIView.
But I think there are two ways to use for dragging.
Which one is better between UIPanGesture and UIDragInteraction/UIDropInteraction?
Furthermore, I'm not sure about what panning means.
2. what is difference between dragging and panning?
(From Apple site: UIDragInteraction & UIPanGestureRecognizer),
UIDragInteraction
An interaction to enable dragging of items from a view, employing a delegate to provide drag items and to respond to calls from the drag session.
UIPanGestureRecognizer
A concrete subclass of UIGestureRecognizer that looks for panning (dragging) gestures.
Here, Pan & Drag gesture is almost same.
Some of differences which I got from searching are as follow..
UIDragInteraction works from iOS 11.0+ & UIPanGestureRecognizer works from iOS 3.2+, so if you want to run your application in older version devices then you should use UIPanGestureRecognizer
UIPanGestureRecognizer works on the whole screen & gives you the CGPoints as response of touch where UIDragInteraction works on the particular object you want to drag & drop & gives you direct the view object.
UIPanGestureRecognizer can work with multiple touches & handle those where UIDragInteraction doesn't allow you to handle multiple touch.
Hope this helps.
Thanks
I am trying to make a game in SWIFT (SpriteKit) where the user can pick between a large amount of characters to play as during the game. The 'characters' would be in what looks like a horizontal picker view. It is similar to the app "Ball King's" player chooser that looks like this:
and
I do not know where to start and any help would be great! Thank you!
Just set up a UISwipeGestureRecognizer in your view. When a swipe is detected, get the direction of the swipe and either display the next or previous sprite with an animation. If you haven't used gesture recognizers documentation is here. Another option is to simply detect swipes generically using touchesBegan, touchesMoved, etc.
I'm building a tower defence game using SpriteKit and I'm relatively new to this.
My map basically consists of tile Nodes that are touchable. Once a user touches the node, I can place a tower on that node (I have this part working so far). What I want to do moving forward, is instead of directly placing a tower, I'd like a circular menu to pop up around the tile Node to let the user pick the tower that they wish to place in this tile node.If the user clicks anywhere other than the circular menu, the menu should disappear.
So something like this:
http://imgur.com/QvCsM8Q
I'm wondering what the best way to do this is. I have two possible solutions but they seem hacky:
1) Creating a custom UIView consisting of the menu and 4 buttons and then adding it to my scene (but then how do I detect button presses in this menu from the scence?)
2) Extending a SKShapeNode to create a circle and adding in 4 SpriteNodes around the circle, then verifying if a touch location corresponds to one of the 4 SpriteNode locations.
Any suggestions/code examples of how best to approach this?
I would suggest you create a separate class for your tile nodes (which inherit SKSpriteNode) and add the functionality within that.
For the approach for the menu, I think something along the lines of point (2) would be better. By subclassing the tile node, you can make the tile detect the selection by itself.
Expand the tile using SKShapeNode or a SKSpriteNode with a circular image using animation.
Place the four buttons on the expanded part.
Implement the touch for the selection within the tile node class.
For closing the menu, a tap on the scene can trigger a NSNotification for which the tileNode could become a listener on expansion.
I never developed in Cocos2D. However, this animated app is not easy to make with regular UIView animation and CAAnimation.
I want a number of UIImageView's (from 1 to 30) to float around the screen with the certain path and I want them to be responsive for touch (they would do some animation when touched). I also need them to go back and forth the screen (new path would be calculated) when they are touched or reach the edge of screen. It's important to retrieve X and Y position of each element whenever needed.
Question is: what Cocos2D classes are best looking at (for a beginner) to make that happen? I've tried UIView animation and CAAnimation but I came across some difficulties so I have a feeling Cocos2D may bring better results. Thank you.
Yes, cocos2d makes it much easier. You want to create a CCSprite with the initWithFile: method. Example:
CCSprite *mySprite = [CCSprite initWithFile:#"fire.png"];
[self addChild:mySprite];
Where fire.png has been added to the project and self is the scene instance.