sprite-kit

Couldn't make a particle follow a path in spriteKit

我怕爱的太早我们不能终老 提交于 2019-12-21 19:52:10
问题 This is the animation in XCode SKEmitter editor (I want to achieve this on the iPhone) : This is the animation on the iPhone (I don't want this animation): Using this code: let sparkEmmiter = SKEmitterNode(fileNamed: "fireflies.sks") self.addChild(sparkEmmiter) // self is a SKScene var circle: CGPathRef? = nil circle = CGPathCreateWithEllipseInRect(CGRectMake(400, 200, 200, 200), nil) let followTrack = SKAction.followPath(circle!, asOffset: false, orientToPath: true, duration: 3.0) let

Creating transparent gradient and use it as an alpha-mask in SpriteKit

自古美人都是妖i 提交于 2019-12-21 19:30:10
问题 I am trying to make a gradient and use it as an alpha mask. Right now, I am able to make an image similar to this (from black to transparent): This is the code which I use to make all this: private func createImage(width: CGFloat, height: CGFloat) -> CGImageRef?{ if let ciFilter = CIFilter(name: "CILinearGradient"){ let ciContext = CIContext() ciFilter.setDefaults() let startColor = CIColor(red: 0, green: 0, blue: 0, alpha: 0) let endColor = CIColor(red: 0, green: 0, blue: 0, alpha: 1) let

Creating transparent gradient and use it as an alpha-mask in SpriteKit

不羁的心 提交于 2019-12-21 19:30:06
问题 I am trying to make a gradient and use it as an alpha mask. Right now, I am able to make an image similar to this (from black to transparent): This is the code which I use to make all this: private func createImage(width: CGFloat, height: CGFloat) -> CGImageRef?{ if let ciFilter = CIFilter(name: "CILinearGradient"){ let ciContext = CIContext() ciFilter.setDefaults() let startColor = CIColor(red: 0, green: 0, blue: 0, alpha: 0) let endColor = CIColor(red: 0, green: 0, blue: 0, alpha: 1) let

How to duplicate a sprite in sprite kit and have them behave differently

夙愿已清 提交于 2019-12-21 19:20:35
问题 I've been working on a IOS mobile game and I wanted to take an object,duplicate it, and have the copies move all over the screen. I've looked through Google to find things relevant to this but they were all in Objective C or just didn't have what I was looking for. I want to know how to do this in Swift and SpriteKit. 回答1: If you are working with SKSpriteNode you can copy it and all it's current properties with: let copiedNode = nodeToCopy.copy() as! SKSpriteNode You will still need need to

Swift: Make translucent overlapping lines of the same color not change color when intersecting

泄露秘密 提交于 2019-12-21 18:59:44
问题 Currently I have drawn 2 lines on the screen which are the same color but both have an alpha value less than 1. When these lines intersect, the intersection is a different color than the rest of the lines. There was a previous post addressing the same issue: swift drawing translucent lines, how to make overlapping parts not getting darker? However, this post wasn't sufficiently answered. I draw the lines currently like this: var points = [CGPoint]() points = [CGPoint(x: -100, y: 100), CGPoint

Delay when calling SKLabelNode?

做~自己de王妃 提交于 2019-12-21 18:05:49
问题 I am having a problem with a slight delay (lag) when transitioning from one SKScene to another. By commenting out various bit of code I have narrowed this down to SKLabelNode , my guess is thats its loading / caching the font when called which is resulting in a small delay/stutter when stating up the new SKScene . Has anyone else noticed this, its less obvious when your just using a single SKScene (like the default template) as the slowdown just gets lost in the usual startup delay. Does

Delay when calling SKLabelNode?

我怕爱的太早我们不能终老 提交于 2019-12-21 18:04:43
问题 I am having a problem with a slight delay (lag) when transitioning from one SKScene to another. By commenting out various bit of code I have narrowed this down to SKLabelNode , my guess is thats its loading / caching the font when called which is resulting in a small delay/stutter when stating up the new SKScene . Has anyone else noticed this, its less obvious when your just using a single SKScene (like the default template) as the slowdown just gets lost in the usual startup delay. Does

Simplest Way To Change Scene In Swift + Sprite Kit [closed]

不问归期 提交于 2019-12-21 17:39:55
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 4 years ago . I am just wondering what the simplest way to change scenes in Swift + Sprite Kit is? 回答1: when changing between scenes, you're going to need to set up a transition, how the scene will change to the next and define which scene you want to transition to. For the transition, var transition

didBeginContact passed PKPhyicsObject

前提是你 提交于 2019-12-21 17:18:37
问题 I have a helper method which extends SKPhysicsContact extension SKPhysicsContact { /// - returns: `[SKPhysicsBody]` containing all the bodies that match `mask` func bodiesMatchingCategory(mask: UInt32) -> [SKPhysicsBody] { let bodies = [bodyA, bodyB] return bodies.filter { ($0.categoryBitMask & mask) != 0 } } } in didBeginContact() I call this method on the passed in contact . func didBeginContact(contact: SKPhysicsContact) { let ballMask: UInt32 = 0x1 << 2 let ball = contact

Accessibility (Voice Over) with Sprite Kit

随声附和 提交于 2019-12-21 16:55:16
问题 I'm attempting to add support for Voice Over accessibility in a puzzle game which has a fixed board. However, I'm having trouble getting UIAccessibilityElements to show up. Right now I'm overriding accessibilityElementAtIndex , accessibilityElementCount and indexOfAccessibilityElement in my SKScene. They are returning an array of accessible elements as such: func loadAccessibleElements() { self.isAccessibilityElement = false let pieces = getAllPieces() accessibleElements.removeAll