SKJoystick is a retro-arcade joystick for SpriteKit
Available directions:
SKJoystick is a library written in Swift to create a typical retro arcade joystick for SpriteKit. Using a couple of textures , the famous SKEase library to simulate the elastic bouncing animation. I've added also three buttons to have a complete control scene to move your hero, jump, fire and made other actions..
Creating a joystick node :
- convenience init(texture: SKTexture?, color: SKColor = .clear, size: CGSize = CGSize(width:200.0,height:200.0),knob:String! = "blueKnob.png") {
Initializes a new SKSpriteNode object aka our joystick.
- 8 directions: up, down, left, righ and diagonals
- change color, alpha and size
- knowing in time real the directions and the releasing through delegate methods
- new knob textures
- iOS 9.0+
- Xcode 9.2+
- Swift 4.0+
- If you found a bug, open an issue.
- If you have a feature request, open an issue.
- If you want to contribute, submit a pull request.
Add the source folder to your project and use it.
class GameScene: SKScene, SKJoystickDelegate {
var joyStick : SKJoystick!
override func didMove(to view: SKView) {
// Show joystick
let joySize = CGSize(width:300,height:300)
joyStick = SKJoystick.init(texture: nil, color: .clear, size: joySize, knob:"blueKnob.png")
self.addChild(joyStick)
joyStick.zPosition = 1
joyStick.alpha = 0.5
joyStick.position = CGPoint(x:self.frame.width/7,y:self.frame.height/4)
joyStick.isUserInteractionEnabled = true
joyStick.delegate = self
}
Follow the example located to GameScene.swift
to understand the delegate methods (really simple to use..), the property direction
contain one of these constants:
enum Sense: Int {
case UP = 0
case UP_RIGHT = 1
case RIGHT = 2
case DOWN_RIGHT = 3
case DOWN = 4
case DOWN_LEFT = 5
case LEFT = 6
case UP_LEFT = 7
case RELEASED = 8
}
SKJoystick is released under the MIT License