SpriteKit

RSS for tag

Drawing shapes, particles, text, images, and video in two dimensions using SpriteKit.

SpriteKit Documentation

Post

Replies

Boosts

Views

Activity

SCNView and SKView showing different colors
An SCNNode is created and used for either an SCNView or an SKView. SceneKit and SpriteKit are using default values. The SceneView has an SCNScene with a rootNode of the SCNNode. The SpriteKitView has a SpriteKitScene with an SK3DNode that has an SCNScene with a rootNode of the SCNNode. There is no other code changing or adding values. Why are the colors for the SCNView less vibrant than the colors for the SKView? Is there a default to change to make them equivalent, or another value to add? I have tried changing the default SCNMaterial but only succeeded in making the image black or dark. Any help is appreciated.
0
0
391
Feb ’24
How to spawn in particles that don't move
I am trying to make an application for the Vision Pro where the particles don't move but rather stay still so that there is no lag. For example I am trying to spawn in a 100 particles here: I want the particles to remain static but spawning in many causes the simulator to lag. Also is there maybe a way i can get a particle system to follow a specific shape like the one i have in the image. Currently, I have multiple model entities that take on a particle system component for i in 0..<100 { let newEntity = ModelEntity() var particleSystem = particleSystem(color: newColor) newEntity.components.set(particleSystem) newEntity.position = position newEntity.scale = scale stars.append(newEntity) } } func particleSystem(color: UIColor) -> ParticleEmitterComponent { var particles = ParticleEmitterComponent() particles.emitterShapeSize = .init(repeating: 0.02) // make burst smaller particles.emitterShape = .sphere particles.mainEmitter.birthRate = 1 particles.mainEmitter.lifeSpan = 2 particles.mainEmitter.size = 0.02 particles.burstCount = 50 particles.speed = 0.01 particles.mainEmitter.isLightingEnabled = false particles.mainEmitter.color = .constant(.single(color)) return particles }
0
0
429
Mar ’24
Orientation of UIImage image is not reflected in SKTexture
I'm trying to add an image in UIImage format to SpritKit's SKSpriteNode. When converting a UIImage into a texture to SKTexture and adding it to SKSpriteNode, the image that takes into account the orientation of the image held by the UIImage is not displayed on the screen. I tried the code below, but the result is identical. Code1: let image: UIImage? let texture: SKTexture = SKTexture(image: image!) ver imageNode = SKSpriteNode(texture: texture) Code2: let image: UIImage? let cgImage = image?.cgImage let ciImage = CIImage(cgImage: cgImage!) let orientedImage = UIImage(cgImage: CIContext(options: nil).createCGImage(ciImage, from: ciImage.extent)!, scale: 0, orientation: image!.imageOrientation) let texture: SKTexture = SKTexture(image: orientedImage) ver imageNode = SKSpriteNode(texture: texture) Code3: let image: UIImage? guard let cgImage = image?.cgImage else { return } let orientedImage = UIImage(cgImage: cgImage, scale: image!.scale, orientation: .up) let texture = SKTexture(image: orientedImage) ver imageNode = SKSpriteNode(texture: texture) Is there a way to ensure that the image orientation is taken into account when displayed?
1
0
358
Apr ’24