sprite-kit

Stop SKSpriteNode from slowing down

…衆ロ難τιáo~ 提交于 2019-12-06 03:38:42
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 *node, BOOL *stop) { SKSpriteNode *ball = (SKSpriteNode *)node; if (ball.physicsBody.velocity.dx < 0) { if

Game Center integration with Sprite Kit?

允我心安 提交于 2019-12-06 03:34:30
How can I use Game Center or the GameKit Framework with a Sprite Kit Xcode template? In Sprite kit, it uses Scenes; but normally to view the leaderboards for example you need to "presentModalViewController" but that is not possible in SKView. And how can I authenticate the player and all that other fun stuff in iOS 6. Thanks in advance! you can authenticate like this [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) { if (error == nil) { static_setEnable( true ); NSLog(@" Authenticate local player complete"); } else { static_setEnable( false ); NSLog(@

draw a straight line in swift 3 and core graphics

*爱你&永不变心* 提交于 2019-12-06 03:34:16
I'm trying to draw a single, straight line using core graphics and swift 3 However, when touchesmoved is called, it creates multiple lines instead of just a single line. Code used is below: import UIKit class ViewController: UIViewController { @IBOutlet weak var drawingPlace: UIImageView! var startTouch : CGPoint? var secondTouch : CGPoint? override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { let touch = touches.first startTouch = touch?.location(in: drawingPlace) } override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { for touch in touches{

Drawing dashed line in Sprite Kit using SKShapeNode and CGPath

假装没事ソ 提交于 2019-12-06 03:28:18
问题 I want to draw a dashed line in my sprite kit game, I can use SKShapeNode node to draw a normal line like the following: UIBezierPath *_path=[UIBezierPath bezierPath]; //1 CGPoint point1 = CGPointMake(100,100); CGPoint point2 = CGPointMake(150,150); [_path moveToPoint:point1]; [_path addLineToPoint:point2]; //2 SKShapeNode *line = [SKShapeNode node]; line.path = _path.CGPath; I tried to set a dashed pattern to UIBezierPath like this: // adding this code at location 1 or 2 above but no effect

Issue comparing UIColors in Swift

谁说胖子不能爱 提交于 2019-12-06 03:07:02
问题 I need to compare two UIColors, but for some reason it always return false. I tried to compare using == and .isEqual() , but neither of them seem to work. //This is a sample of the colors I have created let blue_color = UIColor(red: 122/255, green: 180/255, blue: 190/255, alpha: 1) //This is the SpriteNode I have to compare let square = SKSpriteNode(color: randomColorController(), size: ksquaresize) randomColorController() is just a function that randomizes colors and returns it, so it is

Swift + Physics: Wrong angle calculation on collision

女生的网名这么多〃 提交于 2019-12-06 02:52:08
问题 I have a simple SpriteKit App with walls and a ball. Both setup with a SKPhysicsBody . When I apply a force in one direction, I expect the ball to reflect at the wall with the same angle when it collide but in opposite direction. But sometimes I see the angle is weird. I played a lot with all the physicsBody properties, but was not able to fix it. Sometimes the first reflections look good, but then the third or sixth and sometimes the first reflection is at wrong angle. I read from different

Spritekit - Create a “wall”

不打扰是莪最后的温柔 提交于 2019-12-06 02:46:59
I am wondering how it is possible to create a wall with spritekit. Something at an object cannot move past. I know that I can use this code: self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame]; ...but when I use that code I basically get a "floor" as well. I want objects to be able to pass through the bottom of the screen but not be able to leave the side. Thanks in advance for any help! Best Regards, Louis. It sounds like you need 2 physics body, one for each side of the screen. Try having something like. // Left Wall SKNode *node = [SKNode node]; node.physicsBody =

Sprite Kit Scene Editor GameScene.sks scene width and height

徘徊边缘 提交于 2019-12-06 02:36:54
问题 I'm using the spritekit scene builder to build my scene (aka the GameScene.sks file when you create the project in xcode 7 ios9). SpriteKit only uses pixel values when setting the screen height and width. My question is this: If I set the pixels values to that of an iphone 6, will the game be too small for ipad and iphone 6+? Why is there no option to fit the device screen? What should I do to avoid this? 回答1: Pixel density First of all the size of the Scene is defined in Points not Pixels .

Does Sprite Kit render in the background, or on the main thread? How does it work?

≡放荡痞女 提交于 2019-12-06 01:47:08
问题 The documentation shows a simplified runloop of Sprite Kit. I am trying to understand how they implemented it. A SKView calls -update: on a SKScene. This then first evaluates actions, then simulates physics, and lets the subclass adjust the scene. After changes are made to the scene, SKView finally renders the node tree to the screen. What I don't understand are the fine details. Does Sprite Kit decouple scene calculations from scene rendering by using different threads or GCD queues? Does it

EaseOut action with custom SKAction

时光怂恿深爱的人放手 提交于 2019-12-06 01:43:02
问题 I have the following custom SKAction working but as an EaseIn instead EaseOut. I want it to EaseOut! I have failed miserably to correct it using various easing equations found around the web. let duration = 2.0 let initialX = cameraNode.position.x let customEaseOut = SKAction.customActionWithDuration(duration, actionBlock: {node, elapsedTime in let t = Double(elapsedTime)/duration let b = Double(initialX) let c = Double(targetPoint.x) let p = t*t*t*t*t let l = b*(1-p) + c*p node.position.x =