SKPopMenu: Swift tile-based menu for SpriteKit
Swift
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
SKPopMenuExample.xcodeproj
SKPopMenuExample
LICENSE
LICENSE.md
README.md

README.md

SKPopMenu 🎈

Swift tile-based menu for SpriteKit

Features

  • Supports 1-6 menu items
  • Customize each menu item with a color and a label or sprite.

Installation

Drag and drop SKPopMenu.swift into your Xcode project

Usage

In your SKScene, add the following:

let pop = SKPopMenu(numberOfSections:6, sceneFrame: self.frame)
self.addChild(pop)

Note: If you choose an odd number of items, the top-most item will be fullscreen width.

To set all sections to the same color:

pop.setColor(SKColor.magentaColor())

To set a specific color to section 1:

pop.setSectionColor(1, color: SKColor.magentaColor())

To change the text label of section 3:

let myLabel = SKLabelNode()
myLabel.text = “hello”
pop.setSectionLabel(3, label:label)

To add a sprite to section 5:

pop.setSectionSprite(5, sprite:SKSpriteNode(imageNamed:”pop”)

To change the name of section 6:

pop.setSectionName(6, text:”Contact”)

To show the menu:

pop.slideUp(0.2) // duration is NSTimeInterval

To hide the menu:

pop.slideDown(0.2) // duration is NSTimeInterval

Show/hide example:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
  if pop.isShowing {
    pop.slideDown(0.2)
  } else {
    pop.slideUp(0.2)
  }
}

Delegate methods (optional)

Add the protocol to your SKScene’s class definition:

GameScene: SKScene, PopMenuDelegate {}
Remember to set pop.popMenuDelegate = self

To get notified when a section is tapped:

func sectionTapped(index:Int, name:String) {
  if pop.sections[index].name == "email" {
    // email section tapped
  }
}

To get notified when the menu has appeared/disappeared:

func popMenuDidAppear() {
  // pop menu appeared
}
 
func popMenuDidDisappear() {
  // pop menu... wait for it... disappeared 😱
}