Giter Site home page Giter Site logo

skgamepad's Introduction

SKGamePad

SKGamePad is a simple-to-use SpriteKit framework that provides an on-screen gamepad.

License Platforms Carthage compatible

SKGamePad is built from ground up with Swift and extends SKNode and SKSpriteNode. This framework adds convenience class to initializ and listen to gamepad touch event.

  • Compatible with Xcode 9 and Swift 4

Features

  • Fully documented.
  • Convenience class SKColorButton: SKSpriteNode creates retangular button that listens for touch events.
  • Convenience class for creating button from textures or images.
  • Convenience class SKDirectionalPad: SKNode creates a node that contains 4 conventional direction button.
  • Convenience class for creating utilities button such as A, B, X, Y on conventional gamepad.

Requirements

  • iOS 9.0+
  • Xcode 9.0 / Swift 4.0

Installation

For Carthage installation

  • Create a Cartfile in the root of your project and add: github "phuocpeter19/SKGamePad"
  • Then run carthage update on Terminal.

For manual installation

  • Download the latest release of this repo and add it to your Xcode project.

Usage

Create a color button

class Scene: SKScene {
    ...
    override func didMove(to view: SKView) {
        let button = SKColorButton(name: SKDirectionalPadButtons.upButton.rawValue, color: padColor, size: padSize)
        button.listener = self
        self.addChild(button)
    }
}
extension Scene: SKColorButtonTouchesListener {
    func buttonTouched(button: SKColorButton, withState state: SKColorButtonTouchEvent) {
        // Do something when the button is touched.
    }
}

SKDirectionalPadButtons is a convenience enumeration for conventional d-pad button. It is recommended to use rawValues from the enum to define d-pad button.

  • Implement protocol SKColorButtonTouchesListener method to receive notification of the button's touch events.

Remember to set the listener of the button!

Create an on-screen d-pad

class Scene: SKScene {
    ...
    override func didMove(to view:SKView) {
        let dpad = SKDirectionalPad(padColor: UIColor.blue, padSize: CGSize(width: 100, height: 100))
        // This will position the dpad at the bottom left of the screen while taking care of the safe area insets of new iPhone X.
        dpad.setPositionToBottomLeft(view)
        dpad.delegate = self
        self.addChild(dpad)
    }
}
extension Scene: SKDirectionalPadDelegate {
    func upPadEventTriggered(eventState state: SKColorButtonTouchEvent) {
        // Do something when up button is touched.
        // repeated this for other buttons.
    }
}

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.