Post

Replies

Boosts

Views

Activity

Reply to Avoiding SKView Stretching During Layout Animations
Interested in a solution to this issue as well. override func didMove(to view: SKView) { scaleMode = .resizeFill view.contentMode = .center // This is the closest working solution indeed. But not quite there yet. } The documentation of setNeedsDisplay() method says: If your view is backed by a CAEAGLLayer object, this method has no effect. A CAEAGLLayer is "a layer that supports drawing OpenGL content." SpriteKit probably used that, then moved to Metal, and the same limitation still applies. But this is only speculation. Source: setNeedsDisplay() CAEAGLLayer
Topic: Graphics & Games SubTopic: SpriteKit Tags:
Oct ’24
Reply to SF Symbols work with SpriteKit on iOS?
I also use SF Symbols with SpriteKit for quick UI and icon prototyping. I have an SKTexture extension to create SpriteKit textures from SF Symbol on iOS: extension SKTexture { convenience init?(systemName: String, pointSize: CGFloat, weight: UIImage.SymbolWeight = .regular) { let config = UIImage.SymbolConfiguration(pointSize: pointSize, weight: weight) guard let symbol = UIImage(systemName: systemName)?.applyingSymbolConfiguration(config) else { return nil } let rect = CGRect(origin: .zero, size: symbol.size) UIGraphicsBeginImageContextWithOptions(rect.size, false, 0) guard let context = UIGraphicsGetCurrentContext() else { return nil } /// Flip the coordinate system context.translateBy(x: 0, y: rect.size.height) context.scaleBy(x: 1, y: -1) /// Generate a white image UIColor.white.setFill() context.fill(rect) context.setBlendMode(.destinationIn) if let cgImage = symbol.cgImage { context.draw(cgImage, in: rect) } else { return nil } guard let result = UIGraphicsGetImageFromCurrentImageContext() else { return nil } self.init(image: result) } } Usage example: let iconTexture = SKTexture(systemName: "play.fill", pointSize: 17, weight: .bold) let sprite = SKSpriteNode(texture: iconTexture) sprite.colorBlendFactor = 1 sprite.color = .systemBlue addChild(sprite)
Topic: Graphics & Games SubTopic: SpriteKit Tags:
1w