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
3
votes
1 answer

How to prevent SpriteKit overlay in SceneKit to stretch?

In WWDC 2017 SceneKit session they recommend using overlaySKScene to overlay a SpriteKit layer over SceneKit for HUD, etc. It seems to work fine until I rotate the iPhone/iPad. Now the text in SpriteKit all got stretched (if turn from portrait to…
Lim Thye Chean
  • 8,704
  • 9
  • 49
  • 88
3
votes
2 answers

How to call a color sprite to a certain position (Swift 3)

So within my project, I am basically trying to make a randomly generated maze with random entrances and exits. I have three classes (a Maze class, a GameScene class, and a Grid Class) within so far I have successfully been able to code a randomly…
3
votes
2 answers

extension for SKPhysicsContact crashing

I'm creating a game with SpriteKit, that has collision between 2 bodies. After setting up the bodies, I've implemented the didBegin(_contact:) moethod as shown below: func didBegin(_ contact: SKPhysicsContact) { if contact.bodyA.categoryBitMask…
Fayyouz
  • 682
  • 7
  • 18
3
votes
0 answers

AVPlayer autostart in SceneKit

I have an AVPlayer used in SpriteKit as a material of SceneKit node. However, the AVPlayer will always auto start! I have tried to put the code in viewDidLoad or viewWillAppear (as some answers), but it still load automatically. My code is something…
Lim Thye Chean
  • 8,704
  • 9
  • 49
  • 88
3
votes
1 answer

SpriteKit: callback when scene is done presenting?

In SpriteKit, is there a callback when a scene has completed its transition? It doesn't appear like the SKView presentScene function has a callback. The alternative is to have the scene manually notify the caller after the scene moves into view, but…
Crashalot
  • 33,605
  • 61
  • 269
  • 439
3
votes
1 answer

How to touch and hold a node in Swift?

I am currently working on a project in which I need the user to press on a node to make an action occur. So currently I am working with some code that will allow this to happen but only if the user touches the screen. I want it to work when the…
Balaach
  • 125
  • 1
  • 6
3
votes
1 answer

Argument of '#selector' does not refer to an '@objc' method (swift 3)

I am setting up swipe recognition in my SKScene, and I found that hard coding all the recognizers takes time and isn't really neat, so I decided to use a for-loop, and a dictionary that contains UISwipeRecognizers as keys, and () functions as…
Fayyouz
  • 682
  • 7
  • 18
3
votes
1 answer

Is it safe to change `SKNode`s in a gesture recognizer action method?

Apple states in https://developer.apple.com/documentation/spritekit/skscenedelegate : Modifying SpriteKit objects outside of the ordained callbacks (a background queue or anything else non-main-thread) can result in concurrency related…
Klaas
  • 22,394
  • 11
  • 96
  • 107
3
votes
0 answers

Add delay to SKEmitter or SKReference to Scene editor

I'm trying to sempificate some animation with scene kit. I want to achieve to have an SKEmitter to the scene after some delay. The SKEmitter has a limitated number of spawn emitter, so it is during just 1 second, but I want this animation after 2…
Simone Pistecchia
  • 2,746
  • 3
  • 18
  • 30
3
votes
1 answer

Swift - Overlaying a SKScene onto a UIView - Grey Background

I'm new to Swift and Xcode and am just playing around with SpriteKit. What I did is that I created a UIView in main.storyboard. The UIView (named overlayedGameScene) is only taking up about half of the screen, so you should be able to see the main…
K King
  • 71
  • 4
3
votes
1 answer

How to rotate SKLabelNode in company with its parent SKShapeNode?

When press the screen, balls created with the following codes: var n = 1 func addBall(_ x:CGFloat){ let numShape = SKShapeNode(circleOfRadius: 30) numShape.name = "ball" numShape.position = CGPoint(x: x, y: frame.maxY-40) …
jdleung
  • 1,088
  • 2
  • 10
  • 26
3
votes
0 answers

SpriteKit and C file ( not objective_C file )

How do you call Spritekit functions/variables inside a C file ( .h .c ) ? not objective_C file ( .h .m ) Thank you for your help
hungry
  • 174
  • 8
3
votes
4 answers

Swift Unable to Override Variables in Subclass

I am working on a macOS project in Swift, and I've been having a lot of trouble with overriding variables in a few classes I've made. In classTwo Xcode is presenting the error Cannot override with a stored property 'texture' on the line; override…
Jake3231
  • 703
  • 8
  • 22
3
votes
1 answer

SpriteKit CGPath and SpriteMovement

func zombieAI() { let zombieGreen = SKSpriteNode(imageNamed: "Zombie") zombieGreen.setScale(0.3) zombieGreen.zPosition = 3 zombieGreen.physicsBody?.affectedByGravity = false //change this later zombieGreen.position = CGPoint(x:…
B.Toaster
  • 169
  • 2
  • 13
3
votes
1 answer

How to put a scene in a scene - Sprite Kit

I am coming from HTML and javascript development, and in HTML, we have the iframe tag. I was wondering if I could put a scene in a SKNode the same way that the iframe works. Any help would be appreciated.
KingCoder11
  • 415
  • 4
  • 19