I am implementing a horizontal carousel-style character selection screen for a game (as per image below).
The app is structured as one main GameViewController
presenting different scenes; the CharacterSelectionScene
being one of them.
From my research it seems that, although not always advisable to mix UIKit
and SpriteKit
elements, the best way to achieve the effect is the use a UIColectionView
and add it as a subview to the scene. Because it takes care of the some of the animation and bounce effects.
Horizontal scrolling in SpriteKit (vs. a viewcontroller)
However, it's giving me a real headache! Using the post above as an example, I subclassed UICollectionView
but I am unable to use the CharacterSelectionScene
as the datasource and delegate! This would be ideal as the scene is where the data is loaded in from a plist.
I am currently using my CharacterCollectionView
as the datasource and delegate by passing data from the scene via the collection view's init()
a la:
collectionView = CharacterCollectionView(frame: customFrame, collectionViewLayout: layout, characterData: characterData)
This works but feels like a bad idea, it feels like a bit of a bodge. Maybe I'm wrong but as a fairly new programmer I'd just like to do this the right way!
Can anyone point me in the right direction? Am I going down completely the wrong path here or is this a perfectly good way to move forward. All advise/pointers appreciated!