A page control for use in SpriteKit games written in Swift.
This control is used in:
| Demo |
|---|
![]() |
Using a UIPageControl in a SpriteKit game is complex. GBPageControl provides a SpriteKit based page control for you to use in your games with less complexity.
-
Add the GBPageControl framework to your project.
-
Declare a PageControl in your SKScene:
import GBPageControl
var pageControl:PageControl!- Add the page control to the scene. Add any content that will be paged directly to the pageControl:
override func didMove(to view: SKView) {
super.didMove(to: view)
pageControl = PageControl(scene: self)
addContent()
pageControl.enable(numberOfPages: 4)
}
private func addContent() {
for i in 0..<4 {
let node = SKShapeNode(circleOfRadius: 10)
node.strokeColor = .blue
let x = size.width / 2.0 + size.width * CGFloat(i)
let y = size.height / 2.0
node.position = CGPoint(x: x, y: y)
pageControl.addChild(node)
}
}- Call
pageControl.handleTouchintouchesBegan:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else { return }
if pageControl.handleTouch(touch: touch) {
// no op, page control handled it
}
else {
// handle touch in your game scene
}
}- Call
pageControl.willMoveFromViewinwillMoveFromView:
override func willMove(from view: SKView) {
super.willMove(from: view)
pageControl.willMove(from: view)
}-
xMargin - the margin between the page indicators
-
radius - the radius of the page indicators
-
selectedColor - the color of the currently selected page indicator
-
notSelectedColor - the color of the unselected page indicator(s)
-
yPosition - how far from the bottom of the screen the page indicators are displayed
See GBPageControlExample for a working example.
This software is Open Source under the BSD license, see LICENSE.txt for details.
