sprite-kit

SpriteKit - getting closest nodes

戏子无情 提交于 2021-02-07 13:32:45
问题 Is there a way of getting the closest nodes to a node? I'm just about to write a method to iterate all nodes and calculate distances etc... but wondered if there is a better way? I have 30 nodes and need the 2 nearest nodes to each of the 30 nodes (if that makes sense). 回答1: As of iOS 10, you can use the Spatial Partitioning features of GampelayKit. In 2D either GKQuadtree or GKRTree depending on your needs. From the docs: Quadtrees and R-trees have different performance tradeoffs for

SpriteKit - getting closest nodes

删除回忆录丶 提交于 2021-02-07 13:30:48
问题 Is there a way of getting the closest nodes to a node? I'm just about to write a method to iterate all nodes and calculate distances etc... but wondered if there is a better way? I have 30 nodes and need the 2 nearest nodes to each of the 30 nodes (if that makes sense). 回答1: As of iOS 10, you can use the Spatial Partitioning features of GampelayKit. In 2D either GKQuadtree or GKRTree depending on your needs. From the docs: Quadtrees and R-trees have different performance tradeoffs for

SpriteKit - getting closest nodes

跟風遠走 提交于 2021-02-07 13:29:25
问题 Is there a way of getting the closest nodes to a node? I'm just about to write a method to iterate all nodes and calculate distances etc... but wondered if there is a better way? I have 30 nodes and need the 2 nearest nodes to each of the 30 nodes (if that makes sense). 回答1: As of iOS 10, you can use the Spatial Partitioning features of GampelayKit. In 2D either GKQuadtree or GKRTree depending on your needs. From the docs: Quadtrees and R-trees have different performance tradeoffs for

Moving Camera in SpriteKit Swift

蹲街弑〆低调 提交于 2021-02-07 03:06:12
问题 I am creating a game in sprite kit using swift, and I am trying to be able to move the SKScene around with a finger because not all of the nodes fit within the scene. I have already created world, overlay, and camera nodes with this code. override func didMoveToView(view: SKView) { world = self.childNodeWithName("world")! if !isCreated { isCreated = true // Camera setup self.anchorPoint = CGPoint(x: 0.5, y: 0.5) self.world = SKNode() self.world.name = "world" addChild(self.world) self.cam =

Moving Camera in SpriteKit Swift

你。 提交于 2021-02-07 03:03:16
问题 I am creating a game in sprite kit using swift, and I am trying to be able to move the SKScene around with a finger because not all of the nodes fit within the scene. I have already created world, overlay, and camera nodes with this code. override func didMoveToView(view: SKView) { world = self.childNodeWithName("world")! if !isCreated { isCreated = true // Camera setup self.anchorPoint = CGPoint(x: 0.5, y: 0.5) self.world = SKNode() self.world.name = "world" addChild(self.world) self.cam =

Defining physicsbody for a curved object

跟風遠走 提交于 2021-01-29 15:20:36
问题 How can I define the physics body of an curved or not rectangle object I know for a rectangle I use ( rectangle of : width,height) And for a circle I use (circle of radius: ) But how can I do this for a different object like this one 回答1: You can use a CGPath like this: let path = CGMutablePath() path.addLine(to: CGPoint(x: 10, y: 10)) path.addArc(center: CGPoint(x: 20, y: 20), radius: 50, startAngle: 20, endAngle: 60, clockwise: true) node?.physicsBody = SKPhysicsBody(edgeLoopFrom: path) You

SpriteKit physics applyImpulse in direction

孤者浪人 提交于 2021-01-29 15:01:49
问题 I am using the spriteKit-s physics engine. I have 2 objects on the screen, (say player and enemy). Now I am trying to use the applyImpulse method on enemy, which is supposed to pull it towards the player. CGFloat radians = [Utilites pointPairToBearingDegrees:self.enemy.position secondPoint:self.player.position]; CGVector vector = CGVectorMake(500*cosf(radians), 500*sinf(radians)); [self.enemy.physicsBody applyImpulse:vector]; However this applies force in wierd directions. Not consistent at

Xcode SpriteKit Game - How to configure the UI for multiple screen sizes during App install

狂风中的少年 提交于 2021-01-29 12:54:50
问题 I'm developing a basic game for IOS using SpriteKit. iPhone devices come in many shapes and colours. The former of which is giving me a bit of a headache. Different sized screens. This is a two part question. Firstly What solutions have other people implemented to achieve a uniform layout over multiple display sizes? The current solution I'm looking at adopting is to find the device type as suggested in one of the solutions here Scale sprite kit game for all devices, I'll be implementing this

Cannot move my avatar at my own defined speed

余生颓废 提交于 2021-01-29 05:13:48
问题 I am unable to move my avatar in my gameScene at my defined speed(set at 40). It looks as if the avatar and the enemy is free floating in space. Here is my code- import SpriteKit public class GameScene: SKScene, SKPhysicsContactDelegate { let playerSpeed: CGFloat = 40.0 let coronaSpeed: CGFloat = 10.0 var mask: SKSpriteNode? var player: SKSpriteNode? var mcorona: [SKSpriteNode] = [] var lastTouch: CGPoint? = nil override public func didMove(to view: SKView) { physicsWorld.contactDelegate =

Could not create physics body in case of running on simulator

点点圈 提交于 2021-01-29 05:12:49
问题 I am creating a game with parallax scroll and the player is animated with texture atlas. I have encountered various problems while trying to assign physicsBody to node with texture atlas initially. Anyway, now, while trying to run the game on the phone (iPhone X, iOS 13.5), everything works but when I try to run it on simulator (iOS13.5), it fails to create a physics body for the ground which is supposed to be created with the following function: func parallaxScroll(image: String, y: CGFloat,