skspritenode

SKPhysicsBody with restitution 0 still bounces

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 17:35:25
问题 I'm am trying to drop the SKSpriteNode with constant speed and without bouncing. Here is the code I'm using: SKSpriteNode *floor = [SKSpriteNode spriteNodeWithColor:[UIColor clearColor] size:CGSizeMake(self.size.width, 1)]; floor.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:floor.size]; floor.physicsBody.restitution = 0.0f; floor.physicsBody.dynamic = NO; floor.physicsBody.allowsRotation = NO; SKSpriteNode* block = [SKSpriteNode spriteNodeWithTexture:[SKTexture textureWithImageNamed

SKSpriteNode : Handling Collision during SKAction

本小妞迷上赌 提交于 2019-12-07 17:00:42
问题 I'm making a little game, and I'm now stuck with the following problem. I'm running an action (followPath type) on a particular node : let followTrack: SKAction = SKAction.followPath(ballPath!.CGPath, duration: ACTION_SPEED) movingBall.runAction(followTrack) But during the animation, if the node collide with another one (like a wall for exemple), the animation stops and there is no collision animation. I tried some things like : func didBeginContact(contact: SKPhysicsContact) { var firstBody:

Stop SKSpriteNode from slowing down

隐身守侯 提交于 2019-12-07 15:32:44
问题 I am trying to keep my SKSpriteNodes moving at a constant speed forever, even after collisions. I have set gravity to 0, friction to 0, and linear and angular dampening to zero, but the Sprites still slowly slow down to zero velocity. How can I keep them moving? Based on the answer below, this is what I have tried: EDIT This code below works! I just had to check if the nodes were going slower than the limit and speed them up. [self enumerateChildNodesWithName:kBallName usingBlock:^(SKNode

Swift SKSpriteNode: Detect Tap / DoubleTap / LongPress

不羁岁月 提交于 2019-12-07 06:56:25
问题 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

Why won't my SKSpriteNodes appear in the scene?

萝らか妹 提交于 2019-12-06 17:33:32
I am trying to add a couple of nodes to the scene. When I run the app I just have the default gray background. Neither of the nodes appear in the scene. Here is what I have: class GameScene: SKScene { override func didMoveToView(view: SKView) { /* Setup your scene here */ let jumper = SKSpriteNode(imageNamed:"Jumper") jumper.xScale = 0.25 jumper.yScale = 0.25 jumper.position = CGPointMake(50, 300) self.addChild(jumper) let blob = SKSpriteNode(imageNamed:"Blob") blob.position = CGPointMake(160, 30) blob.xScale = 0.5 blob.yScale = 0.25 self.addChild(blob) } I have checked the image titles and

Unwrapping optional values: PhysicsBody - Swift SpriteKit

大城市里の小女人 提交于 2019-12-06 06:38:32
So I made some adjustments to the ball in my game and to avoid an unwrapping optional value error, I commmented out the following //didMoveToView self.physicsWorld.gravity = CGVectorMake(0, 0) self.physicsWorld.contactDelegate = self let fieldBody = SKPhysicsBody.init(edgeLoopFromRect: self.frame) self.physicsBody = fieldBody self.physicsBody!.affectedByGravity = false self.physicsBody!.usesPreciseCollisionDetection = true self.physicsBody!.dynamic = true self.physicsBody!.mass = 0 self.physicsBody!.friction = 0 self.physicsBody!.linearDamping = 0 self.physicsBody!.angularDamping = 0 self

How do I convert a PNG with alpha to RGBA4444 for using it in SpriteKit SKTexture?

[亡魂溺海] 提交于 2019-12-06 06:06:56
I have a stack of transparent PNGs that I'd like to use in a SKSpriteNode animation with SKTexture s. I'd need to adjust the memory usage of SKTexture s by reducing texture quality down from RGBA8888 to RGBA4444 . How would I initialize SKTexture with RGBA4444 texture format? Edit: IOS Swift Game Development Cookbook: Simple Solutions for Game Development suggests that SKTexture would support PVRTC files as follows: However, I couldn't get a SKSpriteNode to display a texture generated this way. Luca Angeletti I just tried and in Xcode 8 the option Output Texture Atlas described here is no

Coordinate System in SpriteKit

痞子三分冷 提交于 2019-12-06 05:06:51
I am quite confused with the spritekit coordinate system. I need clarification on two cases. Case 1: When a sprite node is added as child to the scene: SKSpriteNode * blueBall = [SKSpriteNode spriteNodeWithImageNamed:@"hRedBall.png"]; blueBall.name=@"blueball"; blueBall.size=CGSizeMake(75, 75); blueBall.position=point; //I am varying this point [self addChild:blueBall]; I have added the node at different points each time.These are the points I added the node at: (100x100)(200x200)(300x300)(400x400)(900,600) And in my iphone 5 device, they look like this: If you look into 100x100, when I add

Choosing random image for SKSpriteNode

点点圈 提交于 2019-12-06 04:26:32
I am trying to build a simple obstacle jumping app. I want the image for the obstacle to be picked randomly from a set of images. I have tried using a combination of the arc4random_uniform function and switch case but that doesn't seem to update the SKSpriteNode. What am i doing wrong? class PlayScene: SKScene, SKPhysicsContactDelegate{ ... var block3 = SKSpriteNode(imageNamed: "lion") .... } override func update(currentTime: NSTimeInterval) { ..... blockRunner() } func blockRunner() { var imageNamedAnimal = "" var randomIndex = arc4random_uniform(2) switch(randomIndex) { case 0 :

Is there a way to invert the colors of a SKSpriteNode

萝らか妹 提交于 2019-12-06 04:21:42
问题 I was wondering if it was possible to invert the colors (or adjust the hue) of a SKSpriteNode. 回答1: You can invert the colors by applying a CIFilter with an SKEffect node. Something like this should work: SKEffectNode *effectNode = [[SKEffectNode alloc] init]; effectNode.filter = [CIFilter filterWithName:@"CIColorInvert"]; SKSpriteNode *node = yourNode; // Make sure this node doesn't already have a parent [effectNode addChild:node]; [self addChild:effectNode]; Note that an SKScene is an