Swift SKShapeNode shapeWithSplinePoints
init(splinePoints:count:)
takes an UnsafeMutablePointer<CGPoint>
(i.e., a C array of CGPoint
s) and an unsigned integer as its arguments. It also returns an SKShapeNode
object not a CGPathRef
. Try the following...
let p = SKShapeNode(splinePoints: &path, count: UInt(count))
EDIT: Make the following changes as well
let speed:CGFloat = 1.0
let action = SKAction.followPath(p.path, speed: speed)
sprite.runAction(action)
Inherit SKShapeNode
SKShapeNode.init(circleOfRadius:)
is a convenience initializer on SKShapeNode
so you can't call it from a Swift initializer. Swift enforces the designated initializer pattern more strictly than Objective C does.
Unfortunately, it appears the designated initializer for SKShapeNode
is just init
, so you'll need to do something like this:
public class Player: SKShapeNode {
public var playerName : String
private var inventory: [enumObject]
init(nameOfPlayer:String, position:CGPoint, radius: CGFloat) {
playerName = nameOfPlayer
inventory = [enumObject]()
super.init()
self.path = CGPath(ellipseIn: CGRect(origin: .zero, size: CGSize(width: radius, height: radius)), transform: nil)
self.position = position
self.fillColor = SKColor.white
}
// init?(coder:) is the other designated initializer that we have to support
public required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
The code above works for subclassing SKShapeNode
, but given the API that Apple provides and considering how your code might need to change in the future, it might make more sense to create an SKNode
subclass that contains one or more SKShapeNode
s. In this setup, if you wanted to represent the player as more than just a simple circle, you could simply add additional nodes to the player node.
How to populate an SKShapeNode uniformly
Instead of let x = CGFloat(arc4random_uniform(UInt32(size.width * 20))) - size.width / 4
you define how you want your x to be placed, for example:
let y = CGFloat(arc4random_uniform(UInt32(size.height * 90))) - size.height / 100
let x = (i * size.width)
let y = 0
will place your lines in a single straight line along the x axis where y is 0
How to animate the opacity of a SKShapeNode?
Try this:
var fadeOut = SKAction.fadeAlpha(to: 0.1, duration: 0.5)
var fadeIn = SKAction.fadeAlpha(to: 0.5, duration: 0.5)
rect.run(SKAction.repeatForever(SKAction.sequence([fingerScalingSequence, fadeOut, fadeIn])))
Adjust the durations as per your liking
Related Topics
iOS Firebase: Firauthuidelegate.Authui Not Being Called
Sort Dictionary Keys by Value, Then by Key
Disable Https Get Certificate Check in Swift 5
How to Rotate an Object Around Only One Axis in Realitykit
How to Combine Two Nsdictionary in Swift
Error: Extraneous Argument Label 'No1:' in Call
Generics and Functional Programming in Swift
Swift 5 Coredata Predicate Using Uuid
How to Pass Binding to Child View in the New Navigationstack.Navigationdestination
How to Await X Seconds with Async Await Swift 5.5
Cannot Convert Value of Type 'Binding<String>' to Expected Argument Type 'Binding<String>'
Nscollectionviewitem Never Instantiate
Can You Enforce a Typealias in Swift
Error with Parse Query Findobjectsinbackgroundwithblock
Why Can't I Use Subscripting on a Ckrecord Object in Swift