sprite-kit

Sprite Kit app crashes when run on real device and plugged into computer

北战南征 提交于 2019-12-05 10:32:12
I just updated to iOs10 on my test phone and XCode 8. I ran the code migration and was running tests succeessfully on my simulated devices. However, once I started trying to test on my real device things stopped working smoothly. After running my Sprite Kit game for around 5 - 10 seconds it would crash and render the phone inoperable until I unplugged it from the computer. After I unplug it the game runs as normal and is still really smooth. This are the startup notifications printed to the console: 2016-09-15 22:20:49.490959 AppName[411:38688] [DYMTLInitPlatform] platform initialization

Swift SKSpriteNode: Detect Tap / DoubleTap / LongPress

旧巷老猫 提交于 2019-12-05 10:05:40
I'm attempting to create a subclass of SKSpriteNode which can detect user interaction (tap, double tap and hold), then defer to a delegate. This seems to me like a relatively common need, but: The code is incapable of detecting a double-tap without also triggering a single-tap. I haven't found a way to detect hold/long-press actions at all. Am I going about this all wrong? I can't help feeling that SpriteKit should have something standard to handle something so basic. I know there's UIGestureRecognizer, but it doesn't seem very compatible with specific SKNodes rather than UIViews. Here's what

Sprite Kit - Add random Sprite Nodes to the scene with Switch Case

风流意气都作罢 提交于 2019-12-05 10:00:40
问题 I have the following code to create random objects and add them to the scene. At the end the method is repeated after a random delay. -(void)createObjects { // Create random start point float randomStartPoint = arc4random_uniform(4) * 64 + 32; CGPoint startPoint = CGPointMake(self.size.width + 50, randomStartPoint); // Create random object and add to scene switch (arc4random_uniform(2)) { case 0: { SKSpriteNode *crate = [SKSpriteNode spriteNodeWithImageNamed: @"crate"]; crate.physicsBody =

SKCropNode fails when I add extra SKNode children in hierarchy

两盒软妹~` 提交于 2019-12-05 09:34:47
Update: It looks like iOS 10 has fixed this issue. I upgraded to Swift 3 and Xcode 8 and everything is working as expected. I've run into this issue a couple times now and I can't tell if it's a bug in SKCropNode or if I'm just misusing it. Perhaps there's some bit of documentation I'm missing to explain why this is happening? I have a crop node with a 100x100 rectangle shape as the mask. If I place a blue circle inside it, it gets cropped properly. // Create a crope node with a small square. let cropNode = SKCropNode() let cropNodeMask = SKShapeNode(rect: CGRect(x: 0, y: 0, width: 100, height

SpriteKit Weird 'PKPhysicsBody' Crash

泪湿孤枕 提交于 2019-12-05 09:34:06
I am trying to implement a simple category for SKPhysicsBody that will allow me to apply 'perfect bouncing' to a physics body. What this will simply do is when perfectBouncing = YES the following will happen: restitution = 1.0 linearDamping = 0.0 friction = 0.0 However, when I try to use my implementation as shown below, I get a weird crash telling me that I can't send perfectBouncing messages to PKPhysicsBody , which is a class that I never refer to and doesn't exist in my project or to my knowledge in the SpriteKit SDK. And yes, the catagory is being imported. Crash Message -[PKPhysicsBody

Sizing and scaling SKSpriteNode

白昼怎懂夜的黑 提交于 2019-12-05 09:04:38
I have multiple game objects in my iOS game, some of which have a greater resolution than others. The graphics to use for the game object is chosen randomly at runtime. I'd like to make sure that they all don't go over a certain size when used, so I devised the following algorithm: while self.spriteNode.rSize.width > 100 && self.spriteNode.rSize.height > 100 { self.xScale -= 0.01 self.yScale -= 0.01 } where spriteNode is the object whose texture is the graphic and rSize is an extended computed property on SKSpriteNode that returns the size of the accumulated frame of the node. Often, this

SKShapeNode filltexture() does not display image

心已入冬 提交于 2019-12-05 08:23:15
I want to create a circle that whose content is an image (.png), and based on the SKShapeNode class reference, I thought that I could use SKShapeNode.filltexture() function to set the texture to the image. But when i run the code below, I get the circle, but the image of the "cat-black" I am trying to load doesn't show. I checked that my Image.Assets have the image with the correct name, so something else is up. Any ideas? I attached the output below: func newCircle(photo:String, position:CGPoint) -> SKShapeNode { let circle = SKShapeNode.init(circleOfRadius: 27) circle.fillTexture = SKTexture

SKSpriteNode gets hidden below parent node

时光总嘲笑我的痴心妄想 提交于 2019-12-05 08:17:41
Using Swift and SpriteKit, I have a problem with SKSpriteNode not showing when being added as a child to another SKSpriteNode. In contrast, a SKLabelNode put in exactly the same place does show up. // does not show up, expected a white square override func renderBody(parentNode: SKNode, position: CGPoint) { let node = SKSpriteNode(color: UIColor.whiteColor(), size: CGSize(width: 48, height: 48)) node.position = position parentNode.addChild(node) } // does show up as white text in the correct position override func renderBody(parentNode: SKNode, position: CGPoint) { let node = SKLabelNode(text:

How to properly calculate 1 second with deltaTime in Swift

别说谁变了你拦得住时间么 提交于 2019-12-05 08:16:18
I'm trying to calculate an elapsed second in deltaTime but I'm not sure how to do it, because my deltaTime constantly prints 0.0166 or 0.0167. Here is my code: override func update(_ currentTime: CFTimeInterval) { /* Called before each frame is rendered */ deltaTime = currentTime - lastTime lastTime = currentTime How do I make it so I can squeeze some logic in here to run every second? EDIT: I was able to come up with the following, but is there a better way? deltaTimeTemp += deltaTime if (deltaTimeTemp >= 1.0) { print(deltaTimeTemp) deltaTimeTemp = 0 } I always use SKActions for this type of

Jumping to a specific SKNode in node hierarchy

不问归期 提交于 2019-12-05 08:10:05
I have noticed that the SKNode methods children and childNodeWithName: as the name implies only return results from the children directly below the queried node. i.e. [root children]; will return an NSArray containing the nodes @[CUBE1, CUBE2, CUBE3] . In the diagram below I want to get from the ROOT (SKScene) level down to SPHERE2 so that I can quickly access that nodes children. I was hoping that [root childNodeWithName:@"SPHERE2"]; would traverse the whole hierarchy and return a pointer to SPHERE2 MY QUESTION: Is there something that I have missed that will let me jump into a node tree at a