Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/JarWarren/Joystick
A Joystick class for use with SpriteKit. Drag and drop to install. Converts the user's touches to a Direction.
https://github.com/JarWarren/Joystick
game ios joystick mobile spritekit swift
Last synced: 2 months ago
JSON representation
A Joystick class for use with SpriteKit. Drag and drop to install. Converts the user's touches to a Direction.
- Host: GitHub
- URL: https://github.com/JarWarren/Joystick
- Owner: JarWarren
- License: unlicense
- Created: 2020-01-01T19:00:20.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-01T23:01:17.000Z (about 5 years ago)
- Last Synced: 2024-08-10T14:19:19.883Z (6 months ago)
- Topics: game, ios, joystick, mobile, spritekit, swift
- Language: Swift
- Homepage:
- Size: 19 MB
- Stars: 12
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Joystick
*An 8-directional joystick class that sends updates to a delegate. Drag and drop to install. Does not come with assets.*
*I needed a joystick for a SpriteKit demo I was building and couldn't find anything online.*
*I hope that by uploading it to github, someone else may be able to benefit from the way I implemented it - or perhaps even use it directly in their own project.*
![Joystick Demo](Joystick_Demo.gif)### Explanation
My HUD is built in UIKit and sends user input via the delegate pattern.
Joystick is a subclass of UIImageView that reads user touches, determines where in itself they occured, and translates them into a direction.The delegate is only notified when the direciton changes, so that the hero can react accordingly. If the user lets go of the joystick, the delegate receives a `nil` direction. An opportunity to "idle" your hero.
.
### Installation
1. Drag and drop both Swift files into your project.
2. Add a `UIImageView` to your storyboard and subclass it as a `Joystick`.
3. Check the box that says `User Interaction Enabled`. (Or set `isUserInteractionEnabled = true` in Swift).
4. Create an outlet and in `viewDidLoad()`, set your ViewController as the joystick's delegate.
5. Conform to `JoystickDelegate`.*Feel free to make any edits you want. (Ex. rotate a single asset instead of providing one for each direction.)*