Questions tagged [sprite-kit]

SpriteKit is Apple's framework for creating 2D games for iOS 7+, macOS 10.9+, tvOS 9+ and watchOS 3+. It is a 2D rendering engine combined with a physics engine. It is compatible with both Objective-C and Swift.

SpriteKit provides a graphics rendering and animation infrastructure that you can use to animate arbitrary textured images, or sprites. SpriteKit uses a traditional rendering loop where the contents of each frame are processed before the frame is rendered.

SpriteKit is available on iOS (), macOS (), tvOS () and watchOS (). It uses the graphics hardware available on the hosting device to composite 2D images at high frame rates. SpriteKit supports many different kinds of content, including:

  • Untextured or textured rectangles (sprites)
  • Text
  • Arbitrary CGPath-based shapes
  • Video

SpriteKit also provides support for cropping and other special effects; you can apply these effects to all or a portion of your content. You can animate or change these elements in each frame. You can also attach physics bodies to these elements so that they properly support forces and collisions. Physics bodies can be created as rectangles or circles, follow CGPaths, or use an image's alpha to create a more complex physics body.

Since SpriteKit supports a rich rendering infrastructure and handles all of the low-level work to submit drawing commands to OpenGL () or Metal, you can focus your efforts on solving higher-level design problems and creating great gameplay.

Resources:

13201 questions
22
votes
2 answers

CUICatalog: Invalid Request: requesting subtype without specifying idiom (Where is it coming from and how to fix it?)

When I run my SpriteKit game, I receive this error multiple times in the console. As far as I can tell (though I'm not completely sure), the game itself is unaffected, but the error might have some other implications, along with crowding the debug…
22
votes
1 answer

Draw a grid with SpriteKit

What would be the best way to draw a grid like this by using the SpriteKit 2D game engine? Requirements: Input programatically the number of columns and rows (5x5, 10x3, 3x4 etc.). Draw it programmatically using something like SKSpriteNode or…
Alex
  • 2,325
  • 3
  • 29
  • 35
22
votes
1 answer

Optional parameter in class initialization

I'm working with Swift, Sprite-Kit and Xcode 6, I have a class declared like this : class Obstacles: SKSpriteNode { init(initTime: Int, speed: CGFloat, positionX: CGFloat, rotationSpeed: CGFloat) { self.initTime = initTime …
Drakalex
  • 1,488
  • 3
  • 19
  • 39
22
votes
3 answers

My SKLabelNode doesn't change color

I have an SKLabelNode in my iOS app to display a player's score. I want to be able to change the color of it (for now, just to a standard cyan color). But I can't seem to figure out why it's not changing. I have another app where I've used this…
Justgrant2009
  • 603
  • 1
  • 8
  • 18
22
votes
6 answers

How do you stop a particle effect? (SKEmitterNode)

I currently have this code in a collide statement where if collide with object then this particle happens but how do I stop it? As it goes on forever whereas I only want to happen a couple of times per contactetc SKEmitterNode *emitter = …
John B
  • 105
  • 1
  • 2
  • 11
21
votes
2 answers

Add glowing effect to an SKSpriteNode

I have a moving black image on a dark screen, to make it easier to see I would like to add in a white glow to the image. This is my code for the moving image: Ghost = SKSpriteNode(imageNamed: "Ghost1") Ghost.size = CGSize(width: 50, height:…
Oren Edrich
  • 674
  • 1
  • 7
  • 23
21
votes
3 answers

How to set font size of SKLabelNode to fit in fixed size (Swift)

I have a square (200X200) with a SKLabelNode in it. The label shows score and it my be reach a large number. I want fit the number in the square. How can i change text size (or Size) of a SKLabelNode to fit it in a fixed size.
nmokkary
  • 1,219
  • 3
  • 14
  • 24
21
votes
1 answer

SpriteKit Texture Atlas vs Image xcassets

I am making a game and I noticed that during some scenes, my FPS kept dropping around the 55-60FPS area (using texture atlas). This drove me nuts so I decided to put all my assets to the Images.xcassets folder and voila, steady 60FPS. I thought this…
JRam13
  • 1,132
  • 1
  • 15
  • 25
21
votes
5 answers

UIImage from SKTexture

How to get UIImage from SKTexture? I tried to get UIImage from SKTextureAtlas, but it seems not working too: // p40_prop1 is a part of SKTextureAtlas UIImage *image = [UIImage imageNamed:@"p40_prop1"]; image is nil.
Andrey Gordeev
  • 30,606
  • 13
  • 135
  • 162
21
votes
7 answers

iOS 7 Sprite Kit freeing up memory

I am building an iOS game aimed for the new iOS 7 and Sprite Kit, using emitter nodes and physics to enhance gameplay. While developing the app, I ran into a serious problem: you create your scenes, nodes, effects, but when you are done and need to…
Lehel Medves
  • 527
  • 1
  • 5
  • 15
21
votes
1 answer

Is it possible to end an SKAction mid-action?

I have a subclass of SKSpriteNode (monsterNode). It automatically runs around the screen using vectors to follow the player. I am currently using the following action to make it run around: SKAction *actionMove = [SKAction moveTo:actualDistance…
EvilAegis
  • 733
  • 1
  • 9
  • 18
21
votes
8 answers

SpriteKit's SKPhysicsBody with polygon helper tool

I wonder if there is a tool that could be used for easy generation of complex physics bodies in SpriteKit. I would like to have a volume based physical bodies with polygon-type shapes. SpriteKit allows to create such bodies with that method: +…
Darrarski
  • 3,882
  • 6
  • 37
  • 59
20
votes
4 answers

Using SpriteKit inside SwiftUI

I am having an issue when creating a SpriteKit scene within SwiftUI. I created this project initially as a SwiftUI project. Here is the code I have so far: ContentView.swift: /// Where the UI content from SwiftUI originates from. struct ContentView…
George
  • 25,988
  • 10
  • 79
  • 133
20
votes
0 answers

Metal crash upon adding SKSpriteNode to SKEffectNode

> -[MTLDebugRenderCommandEncoder setScissorRect:]:2028: failed assertion (rect.x(0) + rect.width(1080))(1080) must be <= 240 I am getting this crash when adding a simple SKSpriteNode to a SKEffectNode with the following code SKSpriteNode…
user3765506
  • 457
  • 1
  • 5
  • 15
20
votes
6 answers

SpriteKit physics in Swift - Ball slides against wall instead of reflecting

I have been creating my own very simple test game based on Breakout while learning SpriteKit (using iOS Games by Tutorials by Ray Wenderlich et al.) to see if I can apply concepts that I have learned. I have decided to simplify my code by using an…