Giter Club home page Giter Club logo

tlanalogjoystick's Introduction

AnalogJoystick.swift

Preview

Analog joustick

Features

  • Begin handler
  • Tracking handler
  • Stop handler
  • Set/change joystick diameter
  • Set/change stick && substrate colors
  • Set/change stick && substrate images

Manual

  1. Just drop the AnalogJoystick.swift file into your project.
  2. That's it!

Init examples:

init with 100px diameter.Colors & images you can change later

let joystick = AnalogJoystick(diameter: 100)
// or
let joystick = ๐Ÿ•น(diameter: 100)

Substrate has 100px diameter, stick has 50px diameter

let joystick = AnalogJoystick(diameters: (100, 50)) 

init with 100px diameter.Substrate has blue color, stick has yellow color

let joystick = AnalogJoystick(diameter: 100, colors: (UIColor.blue(), UIColor.yellow()))

init with 100px diameter.Substrate has "substrate" image, stick has "stick" image

let joystick = AnalogJoystick(diameter: 100, images: (UIImage(named: "substrate"), UIImage(named: "stick")))

init with 100px diameter.Substrate has blue color && "substrate" image, stick has yellow color && "stick" image

let joystick = AnalogJoystick(diameter: 100, colors: (UIColor.blue(), UIColor.yellow()), images: (UIImage(named: "substrate"), UIImage(named: "stick")))

init with substrate && stick diameters.Substrate has blue color && "substrate" image, stick has yellow color && "stick" image

let joystick = AnalogJoystick(diameters: (100, 50), colors: (UIColor.blue(), UIColor.yellow()), images: (UIImage(named: "substrate"), UIImage(named: "stick")))

init with substrate && stick diameters.Substrate has blue color, stick has yellow color

let joystick = AnalogJoystick(diameters: (100, 50), colors: (UIColor.blue(), UIColor.yellow()))

init with substrate && stick diameters.Substrate has "substrate" image, stick has "stick" image

let joystick = AnalogJoystick(diameters: (100, 50), images: (UIImage(named: "substrate"), UIImage(named: "stick")))

Designated initializator

init(substrate: AnalogJoystickSubstrate, stick: AnalogJoystickStick)

WHERE:

  • substrate - substrate of joystick (AnalogJoystickSubstrate:AnalogJoystickComponent)
  • stick - stick of joystick (AnalogJoystickStick:AnalogJoystickComponent)

Convenience initializators:

convenience init(diameters: (substrate: CGFloat, stick: CGFloat?), colors: (substrate: UIColor?, stick: UIColor?)? = nil, images: (substrate: UIImage?, stick: UIImage?)? = nil)
convenience init(diameter: CGFloat, colors: (substrate: UIColor?, stick: UIColor?)? = nil, images: (substrate: UIImage?, stick: UIImage?)? = nil)

Typealias

typealias AnalogJoystick = ๐Ÿ•น

Example

let joystick = ๐Ÿ•น(diameter: 110) // it's equal let joystick = AnalogJoystick(diameter: 110)

Handlers

  • var beginHandler: (() -> Void)? // before move
  • var trackingHandler: ((AnalogJoystickData) -> ())? // when move
  • var stopHandler: (() -> Void)? // after move

Computed Properties

  • var stickColor: UIColor (get/set)
  • var substrateColor: UIColor (get/set)
  • var stickImage: UIImage? (get/set)
  • var substrateImage: UIImage? (get/set)
  • var diameter: CGFloat (get/set)

Examples

Create joystick

let joystick = AnalogJoystick(diameter: 100) // you can set images/color later

or with images

let joystick = AnalogJoystick(diameter: 100, images: (UIImage(named: "substrate"), UIImage(named: "stick")))

Tracking With Closure

joystick.beginHandler = { [unowned self] in
  // Something...
}

joystick.trackingHandler = { [unowned self] data in
  // Something...
  // data contains angular && velocity (data.angular, data.velocity)
}

joystick.stopHandler = { [unowned self] in
  // Something...
}

Change diameter

  joystick.diameter = 100 // set new diameter

Change colors

  joystick.stick.color = UIColor.yellow() // set yellow color to stick node
  joystick.substrate.color = UIColor.red() // set red color to substrate node

Change images

  joystick.stick.image = UIImage(imageNamed: "yourStickImage") // set image to stick node
  joystick.substrate.image = UIImage(imageNamed: "yourSubstrateImage") // set image to substrate node

License

The MIT License (MIT)

Copyright (c) 2015...2018 Dmitriy Mitrophanskiy

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

tlanalogjoystick's People

Contributors

mitrofd avatar darkcammo avatar imgbotapp avatar sblincov avatar

Watchers

James Cloos avatar

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.