gameplay-kit

SKScene not loaded when add GKComponent to GameScene.sks

我的梦境 提交于 2020-04-17 22:12:03
问题 I am currently creating a 2D game with Swift SpriteKit and GameplayKit. I have a GameScene.sks file and a GameScene.swift file that is of type SKScene. Now I wanted to add a Component of type GKComponent. I created my component and added it to one of my SKSpriteNodes in GameScene.sks However after adding the Component to the SpriteNode in the Scene Editors Inspector the Scene is no longer loaded and the app shows only a grey screen. Is this a known issue in XCode? Is there a way of bypassing

Obstacles With GameplayKit

喜夏-厌秋 提交于 2019-12-24 06:48:25
问题 Here is my question: How can I convert an SKSpriteNode array into an array of GKObstacles so that an agent can appropriately avoid these obstacles by using the goalToAvoidObstacles:(nonnull NSArray<GKObstacle *> *) maxPredictionTime:(NSTimeInterval) /? It seems that the way in which I am creating the GKObstacle array is not allowing the GKGoal to identify these as obstacles correctly, no matter what weight I give to the goal. I have currently several SKNode s that are added to an SKScene

GameplayKit > Scene Editor Navigation Graph > How to use it for pathfinding?

对着背影说爱祢 提交于 2019-12-23 19:25:15
问题 Not long ago, Apple introduced GameplayKit elements to Xcode's Scene Editor, which is great. However, I seem to have issues with the Navigation Graph element: What I try to achieve is to draw a GKGraph from the Scene Editor, retrieve it in code, and use it as a base for pathfinding. So I draw a GKGraph first: Then I retrieve it in GameScene.swift like this: graph = self.graphs.values.first where graphs is a predefined array by Apple to store the GKGraphs from the Scene Editor. So far so good.

Leaks using GKStateMachine in a Subclass

蓝咒 提交于 2019-12-23 01:50:07
问题 I will show you my actual code. It has three elements: a Helper: import SpriteKit import GameplayKit class GameSceneHelper: SKScene { override func didMove(to view: SKView) { } } A subclass of the helper with some game's states: import SpriteKit import GameplayKit class GameScene: GameSceneHelper { lazy var gameState:GKStateMachine = GKStateMachine(states: [ Introduction(scene: self), SecondState(scene: self) ]) override func didMove(to view: SKView) { self.gameState.enter(Introduction.self)

How to access the object of Navigation graph in SpriteKit scene editor

喜夏-厌秋 提交于 2019-12-18 12:05:52
问题 I am working with SpriteKit and draw a scene by the help of the scene editor in xcode. According to SpriteKit, we can use Navigation graph to draw the paths and I am able to draw a path using navigation graph but i am not able to access this object in swift back-end. How to access this Navigation graph object from the scene. 回答1: In the default SpriteKit template the GameViewController has a section in the viewDidLoad function that copies over the Scene Editors Entities and Graphs. class

GKMinmaxStrategist modifies model after return of best move

試著忘記壹切 提交于 2019-12-12 05:14:35
问题 I implemented GKGameModel, GKGameModelPlayer and GKGameModelUpdate protocols in my corresponding classes. After I ask for best move strategist changes my model's board. I understand how it works, making copies of model and tried all moves, but I thought that my "main" model (from copies are made) won't be affected. Here is what I have: let strategist = GKMinmaxStrategist() strategist.maxLookAheadDepth = 0 strategist.randomSource = GKRandomSource() //my model. game is my auxiliary class,

GKObstacleGraph How to Find Closest Valid point?

本秂侑毒 提交于 2019-12-12 01:38:34
问题 In a scenario where user wants to navigate via mouse or touch to some are of the map that is not passable. When sending the point to GKObstacleGRpah FindPath it just returns an empty array. I want the unit to go to closest (or close enough) passable point. What would be an appropriate way to find a closest valid point in GKObstacleGraph . I understand that I can get the GKObstacle so I can enumerate it's vertices, and I know my unit's position... But well... what is the next step ? NOTE: I am

GKGraph Incorrectly Calculates Path with GKGraphNode2D-Subclassed Nodes

二次信任 提交于 2019-12-11 10:07:41
问题 I started investigating this issue with this question which was partially resolved in the iOS 9.2 SDK. However, upon further investigation, I realized that this framework was still not working as expected. In summary, a GKGraph can be constructed with nodes ( GKGraphNode and its subclasses), between which pathfinding costs and paths can be calculated. A GKGraphNode2D is simply a GKGraphNode that sits on and encapsulates its coordinates in a two-dimensional grid. GKGraphNode can be subclassed,

Prevent Location Offset With SpriteKit Camera Node

*爱你&永不变心* 提交于 2019-12-01 12:02:09
I have noticed that the centerOnNode: method as shown, - (void)centerOnNode:(SKNode *)node { cameraOffset = [node.scene convertPoint:node.position fromNode:node.parent]; node.parent.position = CGPointMake(node.parent.position.x - cameraOffset.x, node.parent.position.y - cameraOffset.y); } greatly impacts the relative positioning of child nodes. As soon as this method runs, the child nodes do in fact seem to be impacted. The following image show the logic of NO movement then with moving left and slightly down: I drew a light blue box to estimate the physics body that it seems the paths are

Prevent Location Offset With SpriteKit Camera Node

拜拜、爱过 提交于 2019-12-01 11:21:39
问题 I have noticed that the centerOnNode: method as shown, - (void)centerOnNode:(SKNode *)node { cameraOffset = [node.scene convertPoint:node.position fromNode:node.parent]; node.parent.position = CGPointMake(node.parent.position.x - cameraOffset.x, node.parent.position.y - cameraOffset.y); } greatly impacts the relative positioning of child nodes. As soon as this method runs, the child nodes do in fact seem to be impacted. The following image show the logic of NO movement then with moving left