sprite-kit

Impulse SKSpriteNode depending on touched location Swift 2

℡╲_俬逩灬. 提交于 2019-12-09 01:57:25
问题 I'm learning Swift 2 and I'm making the typical ball game where you hit the ball, it gets an impulse. But i don't want the ball to always go straight through Y coordinate, it wouldn't be fun, i would like to add an impulse depending on the touched location, go through the opposite direction. I attempted this example that ABakerSmith gave to the OP, but what it does is just spin my ball in the same place and baaarely moving it to one side. So i got this code, already detecting the ball Sprite

Scene created in Sprite kit level editor is not working

别等时光非礼了梦想. 提交于 2019-12-09 01:09:06
问题 I'm trying to do this for a while. I have a main scene for a game named PlayScene . I have a pause button there. When player is tapping that button I want to load another scene, named PauseScene. For visualy creating that scene I use Sprite kit level editor. So I have two files PauseScene.swift and PauseScene.sks . But .sks content ( just a background for now) isn't unarchiving. I don't really know where could I make a mistake. So this is my transition via pause button, located in PlayScene

Create an SKTexture from an SKShapeNode

好久不见. 提交于 2019-12-08 23:09:37
问题 Is there a way to create an SKTexture from an SKShapeNode? Shape nodes are known to cause memory issues and I am looking for a way to create a static graphic from them (.png preferably). 回答1: You can use the SKView method called textureFromNode: Here's from the reference : textureFromNode: Renders and returns a Sprite Kit texture that contains the node’s contents. - (SKTexture *)textureFromNode:(SKNode *)node Parameters node A node object representing the content you want to render to the

SKLabelNode removes leading and trailing spaces - How can I stop that?

喜你入骨 提交于 2019-12-08 22:08:18
问题 I wanted to create an SKLabelNode, which is supposed to have always the same length (for a word guessing game). Unfortunately SKLabelNode decides to always cut off any leading and trailing spaces. This behavior is not described in the documentation. How can I avoid/switch off that behavior? 回答1: If you simply want labels to line up so that they are right aligned, then use a right alignment mode. myLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeRight; However, if you are trying

iOS SpriteKit how to create a node with an image from a folder within app bundle?

自古美人都是妖i 提交于 2019-12-08 21:23:38
问题 I'm trying to create a sprite of a random monster where my images are stored in a folder referenced within the main bundle. NSString* bundlePath = [[NSBundle mainBundle] bundlePath]; NSString* resourceFolderPath = [NSString stringWithFormat:@"%@/monsters", bundlePath]; NSArray* resourceFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:resourceFolderPath error:nil]; NSInteger randomFileIndex = arc4random() % [resourceFiles count]; NSString* randomFile = [resourceFiles

iOS: drawbacks of disabling Metal API Validation in order to fix pipeline failed assertion?

对着背影说爱祢 提交于 2019-12-08 21:05:30
Adding a SKEmitterNode to a SceneKit Scene via a SpriteKit overlay generates the following exception: -[MTLDebugRenderCommandEncoder validateFramebufferWithRenderPipelineState:]:1196: failed assertion `For color attachment 0, the render pipeline's pixelFormat (MTLPixelFormatRGBA8Unorm_sRGB) does not match the framebuffer's pixelFormat (MTLPixelFormatBGR10_XR).' This exception occurs on an iPhone 7 device, but does not appear in the simulator. Searching online yielded one valid workaround: disabling Metal API Validation (in Edit Scheme > Options). What are the drawbacks or gotchas with this

SKNode subclass generates error: cannot invoke initializer for type “X” with no arguments

人盡茶涼 提交于 2019-12-08 19:21:47
问题 SKNodes can get initialized with an empty initializer, e.g., let node = SKNode() . Subclassing SKNode , however, breaks this functionality. After subclassing SKNode , Xcode generates this error when attempting to use the empty initializer on the subclass: Cannot invoke initializer for type "X" with no arguments Assuming SKNodeSubclass is a subclass of SKNode , the line let node = SKNodeSubclass() generates this error. Is it possible to subclass from SKNode and also use an empty initializer

SpriteKit playSoundFileNamed crash on iOS 8.3

北战南征 提交于 2019-12-08 16:05:39
问题 I'm seeing some small amounts of SpriteKit playSoundFileNamed crashes from my app's crash log. The crashes happen on iOS 8.3. 0 CoreFoundation __exceptionPreprocess 1 libobjc.A.dylib objc_exception_throw 2 CoreFoundation -[NSException initWithCoder:] 3 SpriteKit +[SKPlaySound playSoundFileNamed:atPosition:waitForCompletion:] 4 SpriteKit +[SKAction(SKActions) playSoundFileNamed:waitForCompletion:] ... And a few related crashes: 0 CoreFoundation __exceptionPreprocess 1 libobjc.A.dylib objc

Most Efficient Way to Check Collisions in didBeginContact

孤街浪徒 提交于 2019-12-08 14:10:47
问题 What's the best way to check for collision using SpriteKit's didBeginContact method. I'm currently checking by class and doing something like this: if let thisMine = nodeA as? Mine { if nodeB is Player { thisMine.explode() } } else if let thisMine = nodeB as? Mine { if nodeA is Player { thisMine.explode() } } I'm doing this a bunch of times in the didBeginContact method because I have lots of different objects that can interact with each other. Is it more efficient to be checking by the bit

In SpriteKit, how is zPosition used for rendering and for hit tests?

馋奶兔 提交于 2019-12-08 13:52:21
问题 Edit: Apple fixed this in iOS8, so it was certainly not expected/intended but a bug. It appears that the zPosition is interpreted differently when used for rendering a node vs when used for determining which node is touched. When I create a hierarchy of parent and childnodes (all with zPosition set), the topmost node for rendering is determined by the summation of all zPositions leading to the node, so nodes from different parents can be interleaved. When determining the topmost node for