This package offers additional node types and effects which you can use in combination with SpriteKit. In addition it provides extensions to make complicated tasks a bit easier and improve the readability of your code.
All sources are written in Swift.
For examples using MoreSpriteKit
, please refer to the demo project MoreSpriteKitDemo
SKNode
that draws specified text over multiple lines, separated per newLine
character.
The text typing can also be animated, meaning each character will be added after a specified interval, creating a typewriter effect.
Use public initializer:
public init(text: String,
horizontalAlignment: SKLabelHorizontalAlignmentMode = .center,
durationPerCharacter: Double = 0.05,
fontSize: CGFloat = 12,
marginVertical: CGFloat = 15.0,
fontColor: SKColor = .white,
fontName: String = "Chalkduster",
skipSpaces: Bool = true
labelWidth: CGFloat = 0.0
finishTypingOnTouch: Bool = false)
Where the text can be separated by new line characters to indicate start of new line.
Specify a specific labelWidth
to wrap all text to a specific width. MSKAnimatedLabel
will create new lines where necessary.
When the specified labelWidth
is to small for a certain CharacterSequence, a fatal error is thrown.
When durationPerCharacter <= 0.0
, all lines will be drawn immediately without any animation.
When finishTypingOnTouch equals true
, all remaining lines will be drawn instantly without any animation when a user taps the label.
SKNode
that draws specified text using an emitter that follows the characters outlines, over a given duration.
Use public initializer:
public init(text: String,
font: UIFont,
emitterName: String,
marginHorizontal: CGFloat = 10.0,
animationDuration: Double = 2.0,
addEmitterInterval: Double = 0.1)
Extension on SKAction allowing to create a spiraling movement. Usage:
SKAction.spiral(startRadius: radius,
endRadius: radius-50,
totalAngle: CGFloat(.pi * 2.0),
centerPoint: .zero,
duration: 1.5)
Extension on SKAction
allowing to create a shake effect.
NB preview as GIF is not very useful, for proper demonstration please see the example application.
Usage:
SKAction.shake(shakeDuration: 0.2,
intensity: arc4random_uniform(40)+10,
duration: 3)
Extension on SKShapeNode
allowing to create a node with an arrow shape.
Usage:
let arrow = SKShapeNode(arrowWithFillColor: randomColor,
strokeColor: randomColor,
lineWidth: 4,
length: 100,
tailWidth: 20,
headWidth: 50,
headLength: 30)
Extension on SKTexture
allowing to create a texture with a radial gradiant. Could be used for example for range nodes, indicating a creatures attack range.
Usage:
let radialGradientSize = CGSize(width: 150, height: 150)
let radialGradientColors = [UIColor.red, UIColor.blue, UIColor.green, UIColor.blue, UIColor.orange]
let radialGradientLocations: [CGFloat] = [0, 0.25, 0.45, 0.65, 1.0]
let radialTexture = SKTexture(radialGradientWithColors: radialGradientColors,
locations: radialGradientLocations,
size: radialGradientSize)
let radialNode = SKSpriteNode(texture: radialTexture)
Extension on SKTexture
allowing to create a texture with a linear gradiant. Could be used for example for a healthbar.
Usage:
let linearGradientSize = CGSize(width: 150, height: 30)
let linearGradientColors: [UIColor] = [.red, .yellow, .green, .yellow, .red]
let linearGradientLocations: [CGFloat] = [0, 0.35, 0.5, 0.65, 1.0]
let linearGradientTexture = SKTexture(linearGradientWithColors: linearGradientColors,
locations: linearGradientLocations,
size: linearGradientSize)
let gradientNode = SKSpriteNode(texture: linearGradientTexture)
- Public extensions on
SKAction
to add atimingMode
or for example arepeatForever
inline. - Public extensions on
Array
to convert it inline to aSKAction.group
orSKAction.sequence
.
Usage:
let actions: [SKAction] = [.run { self.addEmitterLabel() }, .wait(forDuration: 10)]
run(actions.sequence().forever())
- iOS 10.3+
- Xcode 10.1+
- Swift 5+
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift
compiler.
Once you have your Swift package set up, adding MoreSpriteKit as a dependency is as easy as adding it to the dependencies
value of your Package.swift
.
dependencies: [
.package(url: "https://github.com/sanderfrenken/MoreSpriteKit", .upToNextMajor(from: "1.0.0"))
]
If you prefer not to use any of the aforementioned dependency managers you can integrate the desired sources in your project manually, by adding the corresponding Swift files to your project.
We use Swiftlint from Realm to lint our code.
More info can be found on SwiftLint.
Details about the specific settings for this project can be found in the .swiftlint.yml
file.
- If you think that something is missing or would like to propose new feature, please create an issue.
- Please feel free to โญ๏ธ the project. This gives confidence that you like it which stimulates further development and support ๐คฉ
The following games are using MoreSpriteKit:
-
Do you use MoreSpriteKit in any of your applications? Please extend this list by making a PR!