Giter Site home page Giter Site logo

jarwarren / joystick Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 3.0 19.42 MB

A Joystick class for use with SpriteKit. Drag and drop to install. Converts the user's touches to a Direction.

License: The Unlicense

Swift 100.00%
spritekit swift ios game joystick mobile

joystick's Introduction

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

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.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.