sprite-kit

Add SKReferenceNode/SKScene to another SKScene in SpriteKit

筅森魡賤 提交于 2019-12-18 05:12:15
问题 I would like to add a SKScene to my main GameScene. SKReferenceNode seems to be a good solution. I have : - GameScene.sks (main scene) - Countdown.sks (scene to add to GameScene) - Countdown.swift (Custom class, how does to init it? SKScene ? SKReferenceNode ? SKNode) I don't know how to add programmatically my countdown using my class Countdown. I tried: let path = Bundle.main.path(forResource: "Countdown", ofType: "sks") let cd = SKReferenceNode (url: NSURL (fileURLWithPath: path!) as URL)

linking GameViewController.swift to GameScene.swift

不问归期 提交于 2019-12-18 05:06:13
问题 I have created a UI elements on main.storyboard which i require to be hidden until the game is over and the once the player tap the screen to dismiss. Main.storyboard is linked to GameViewController therefor all my IBOutlets and IBActions are in there and all my game code is in GameScene. How can i link the view controller to the scene for that the popup image and buttons only appear when it is game over. Would greatly appreciate some help, I have been stuck on this for quite some time now.

Rotate an object in its direction of motion

﹥>﹥吖頭↗ 提交于 2019-12-18 04:27:28
问题 Is there a relatively simple way to rotate SKSpriteNode so that it is always facing the direction it is moving? My class Gamescene has a system of objects with their relative physicsbodies that apply impulses on each other when they collide. This makes it relatively difficult to keep track of exactly what direction an object is moving in. Some of the objects are also not regularly shaped, which makes things a bit more chaotic. I have tried using trigonometry (e.g. arctangent), but it only

SpriteKit and SceneKit – How to completely pause a game?

我的梦境 提交于 2019-12-18 04:21:49
问题 I succeeded to pause a scene game with this code: override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) { var touch:UITouch = touches.anyObject() as UITouch pauseText.text = "Continuer" pauseText.fontSize = 50 pauseText.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2) /* bouton play/pause */ var locationPause: CGPoint = touch.locationInNode(self) if self.nodeAtPoint(locationPause) == self.pause { println("pause") addChild(pauseText) pause

SpriteKit and SceneKit – How to completely pause a game?

 ̄綄美尐妖づ 提交于 2019-12-18 04:21:46
问题 I succeeded to pause a scene game with this code: override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) { var touch:UITouch = touches.anyObject() as UITouch pauseText.text = "Continuer" pauseText.fontSize = 50 pauseText.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2) /* bouton play/pause */ var locationPause: CGPoint = touch.locationInNode(self) if self.nodeAtPoint(locationPause) == self.pause { println("pause") addChild(pauseText) pause

SKTextureAtlas no longer sharing textures in iOS 10

早过忘川 提交于 2019-12-18 04:16:39
问题 It seems that when pulling textures from a texture atlas, I am now generating new textures instead of using the same texture across different sprites with iOS 10. On iOS 9, this works as expected. Is anyone else experiencing this issue? Perhaps there is a step I missed that is now a part of iOS 10. Notes: I created a sample project and created a new atlas, then just dragged spaceship in @1x, I have also tried preloading, and that did nothing as well. Code: let atlas = SKTexturAtlas(named:

xCode 8.x crashes with “GameScene.sks” file

你离开我真会死。 提交于 2019-12-18 04:12:17
问题 I've downloaded macOS Sierra 10.12 and put it into an VMWare machine. Everything running well, but at xCode, using SpriteKit , whenever I try to open the GameScene.sks file (to put the origin point (0, 0) at the bottom, just like it was before xCode 8), the program crashes immediately. Using VMWare Pro 12; Tried both with xCode 8.1 and 8.2 Beta, same crash. I know theres many cases as mine, but its just annoying that this have no solution. I found this in my VERY DEEP google search, but that

Flipped x-scale breaks collision handling (SpriteKit 7.1)

二次信任 提交于 2019-12-18 03:38:10
问题 I use SKNode's xScale property to flip my sprites horizontally. Now, after updating iOS to version 7.1 horizontal flip causes my objects to sink inside the ground. (See animation below). The problem occurs only with xScale property. Vertical flips work fine. // Init { SKSpriteNode* ground = [SKSpriteNode spriteNodeWithColor:[UIColor blackColor] size:CGSizeMake(winSize.width, 150)]; ground.position = CGPointMake(winSize.width/2, ground.size.height/2); ground.physicsBody = [SKPhysicsBody

Moving Node on top of a moving platform

倾然丶 夕夏残阳落幕 提交于 2019-12-18 02:57:44
问题 I have a moving platform, but when the node is above the platform it doesnt move with the platform horizontally In this article, the problem is explained: Moving Platform Hell http://www.learn-cocos2d.com/2013/08/physics-engine-platformer-terrible-idea/ And in comment there is solutions for Box2D: Kinematic body But what about SpriteKit ? Update I'm moving the platform using let moveHPart1 = SKAction.moveByX(origW, y: 0, duration: moveDuration); let moveHPart2 = SKAction.moveByX(-origW, y: 0,

In swift, how to get memory back to normal after an SKScene is removed?

我与影子孤独终老i 提交于 2019-12-18 02:41:53
问题 I created a simple game with SpriteKit, however every time I run the game, the memory usage in simulator increases about 30mb, but never decreases when the game is finished. When I run the game over ten times the simulator gets slower and slower and eventually crashes. In this simple game I have two controllers and a gamescene: MainController calls GameViewController via a button triggered In GameViewController, gamescene is initialised in this way: class GameViewController: UIViewController