Scroll View in SpriteKit - ios

I want to make a vertical scrolling view for the level selector on my SpriteKit game, I don't know if I have to use UIScrollView or make it using the SpriteKit framework. Please if anyone knows the best way to do it and how let me know. Thanks.

You have several options here.
It is possible to integrate UI elements into SpriteKit, but instead of adding children to self (your scene), you would add subviews to self.view. You would of course, work with the view now instead of a scene so theres a different way of positioning elements which you would have to work out. Theres quite a few examples of how to do this, here's one that might help you.
An alternative is using something like Scroll Kit, which helps you integrate a UIScrollView into SpriteKit very conveniently!
Also check out this question which might be exactly what you're looking for. Hope this helps!

Related

UIImageView Following Another UIImageView Swift

If there is an answer which covers my question, please give me a link to it. Otherwise here is my question:
I am currently running Swift 2.0 (Xcode 7) Sprite Kit Game and would like to know wether it would be possible for a UIImageView to follow another UIImageView.
So when someone swipes in any direction, the first UIImageView will go that direction, and another will follow it like a snake and they all follow the one in front of them.
Edit: I would like to work like a snake. So I have many UIImageViews which represent body parts of the snake (basically small black dots) and whichever direction the head goes in which is controlled by UISwipeGestureRecogniser the others parts follow.
The most easy way is to use UIScrollView with pagingEnabled property enabled. At raywenderlich you can find small tutorial.
Much better way is to use UIPageViewController, example

Autoscrolling in a UIScrollview

I have been only using Xcode 5 for a little while now and I need help when it comes to auto scrolling a UIScrollView. I am using a single view application. I need the screen to scroll down at a pace that speeds up incrementally. Also I need the screen to keep progressing even when the screen is touched. If someone can explain which code goes where it would be great! Your help will be greatly appreciated. :)
Check out this library: https://github.com/danielamitay/DAAutoScroll
It stops to scroll when the user touches the screen and that's the only solution I see possible. I don't even see why you wouldn't want the user to be able to stop the scrolling..
OK, just adding this from your duplicate question.
I suspect the Piano Tiles game is actually using something like Sprite Kit.
This allows a lot more control over thing like "scrolling" speed.
Instead of using a UIScrollView you would use an SKNode as a layer with the buttons added to that parent layer.
Then using the update game loop you can incrementally increase the speed of the movement based on the time since the game started.
In essence... don't use UIScrollView, don't use UIKit, use SpriteKit.
I can see a few options:
1) suggested by Fogmeister, use Sprite Kit instead.
2) see setContentOffset
3) just use a normal view as parent, then have another child view on top with the full content (would be longer than the parent view), create a NSTimer to periodically call a method which scrolls the child view in whatever direction and speed as required.
Note that might need something on top to mask around the child view from showing the suppose-to-be-hidden sections of the child view.
Hope this helps

Custom Scroll view in cocos2d without using uikit

I currently need to create a custom scroll view without using UIKit's scrollview in cocos2d.
The best way, I think, is to create a separate layer and then add all my sprites to that layer. But I'm not sure how to receive touch events for all of the sprites. Is there a best way to do this? Thanks!
Have you seen CCScrollLayer? It might not be suitable for you but maybe you can copy the way that it is picking up touches.
https://github.com/cocos2d/cocos2d-iphone-extensions/tree/develop/Extensions/CCScrollLayer
http://www.cocos2d-iphone.org/forum/topic/17118
There's another one here as well, not sure if it's a fork or an independent one:
https://github.com/jerrodputman/CCKit
But I didn't have much success with any of these. The bounce and other parts of the experience never feel right, so I go back to using UIScrollView to handle the touches.
I've been facing the same issue and I found the SWScrollView here:
https://github.com/saim80/Cocos2D-Extensions
met my needs better than CCScrollView. It acts more like the UIScrollView where as CCScrollView is more for paging from what I've seen.
There is a nice framework called CMMSimpleFramework.
http://www.cocos2d-iphone.org/forum/topic/39018
http://www.cocos2d-iphone.org/forum/topic/60354
There are some sample videos, and the link to the repo is on those pages.
One of the classes is a scrolling layer that might do what you need.
To get the sample project to run, I had to comment out some game center authentication handler code that has changed, but after I did that the demo worked fine.

Scrolling items on screen [iOS cocos2d]

OK so in my game I need the users to scroll between items, just like you scroll a web page in Safari. Is there any way to do that? If not, maybe scrolling them to the side, like you do in the spriboard? Thanks.
I am not really sure I have understood what you would like to do, but there is a cocos2d extension that seems appropriate to it: CCScrollLayer.
CCLayer subclass that lets you pass-in an array of layers and it will then create a smooth scroller. Complete with the “snapping” effect.
If you are looking for a generic scrolling within your view, I suggest this tutorial or this topic rom cocos2d list.
EDIT:
I have never done it, but I think it should be possible to scale the CCScrollLayer to the size you need.
Otherwise, you might change the contentSize of the layer, or even put the CCScrollLayer into a clipping node.
Anyway, I think that it is much easier to start from this and find a way to adapt it to your specific requirements than start from scratch.

Hierarchy of iOS App UI

I am getting confused reading about CALayers, UIViews and View Controllers. Can someone explain the relationship each of those have to each other (and include anything I might have missed?).
I am particularly interested in a View that may have more than one layer. Does that mean the the View Controller has multiple UIViews or that the UIView has more than one CALayer? Or, does the UIView have another UIView subview?
Thanks for the help guys.
Edit: I guess I should have mentioned I am going to be setting these guys up programmatically, which is why I need to actually understand the relationships instead of relying on IB to do all the heavy lifting for me.
Have you read
http://tuvix.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/LayerTreeHierarchy.html ?

Resources