skscene

Global function call in Swift? Howto?

荒凉一梦 提交于 2019-12-13 00:40:13
问题 I have a Swift noobie question on class method calls. I'm building a simple learning app for my kids using Sprite Kit. I have a global variable scoreCount defined in GameScene, where I pretty much do all my game logic such as detect correct answer and increment scoreCount. I also have GameOverScene. On both I show the Score -label. I'm keeping count of scores with the scoreCount-parameter (in GameScene). However as I'm quite new to Swift and Sprite Kit, I'm wondering how should I update the

Position of mouse click relative to scene, not window

有些话、适合烂在心里 提交于 2019-12-12 12:48:07
问题 In my game I need to use the mouse to select units. However, I am encountering problems as I do not know how to get the coordinates of the click relative to the game, not to the window. For example, if Unit 1 is at the (0,0) point of the game, it could be at any point on the window depending on how I pan and zoom the window, but I want the mouse click to return (0,0) no matter how I move the window as long as I click on the same spot. Right now I am using: override func mouseDown(with event:

Presenting a scene in SpriteKit without discarding the previous?

大憨熊 提交于 2019-12-12 08:54:36
问题 My situation is that I have a GameMenuScene and after the user chooses a level, I want to present the LevelScene . But I do not want to have the previous GameMenuScene discarded because the LevelScene is actually a @property of GameMenuScene and whether or not the user completes the level is to be saved as a @property of LevelScene , which the GameMenuScene should be able to access after the user finishes or exits the level. If I simply use presentScene:transition , the GameMenuScene is

Different iPhone simulator sizes throwing nodes out of place

南楼画角 提交于 2019-12-12 06:06:53
问题 I built my game on the iPhone 6 simulator, and everything was going fine until I needed to switch screen sizes for screenshots. I switched from the 6 to the 5s and now everything is in the wrong place and very off center. How do I make my game suitable for all screen sizes with everything in its place? Will post code if necessary. 回答1: If you have hardcoded your view locations and sizes (as opposed to making everything relative to everything else) then you will either have to refactor to make

SKScene in UIViewController

倾然丶 夕夏残阳落幕 提交于 2019-12-12 03:44:27
问题 I am making this app with multiple features, one of which is supposed to be a game. the normal collision game where you hit objects and score. but my app is a Single based application. when i create a new swift file, how can i add a SKScene to a UIViewController? any help will be appreciated. 回答1: SKScene needs to be added to an SKView which is a subclass of UIView . When you create the view controller, you can either set the view property to be an SKView or add an SKView as a subview, then

Adding Game Center Leaderboard

旧城冷巷雨未停 提交于 2019-12-12 02:15:59
问题 I am new to Swift and am having trouble adding a Game Center leaderboard into my Sprite Kit game. I created a button for the leaderboard but it is in an SKScene and it seems that the code for Game Center needs to be inside a View Controller? I have added the code into my single View Controller, but now I'm not sure where to go. Again, I am very new to this and completely lost -- any help would be greatly appreciated. 回答1: you could create a cocoa touch class with the UIViewController Subclass

Why does setting frameInterval on a SKView not work?

眉间皱痕 提交于 2019-12-11 13:43:56
问题 I'm trying to reduce the framerate to a maximum of 30 FPS. The official documentation says to use: skView.frameInterval = 2; I read through all the available documentations as well as every similar question asked here on stackoverflow or in other pages/blogs/etc. I tried it in so many ways but where ever I tried to set the property it did not affect the FPS. I am not using any other timing mechanisms than those from SpriteKit. I am setting it up accordingly to the documentation and to the

Error Could not cast value of type UIView to SKview

☆樱花仙子☆ 提交于 2019-12-11 13:37:14
问题 Ever since i added in iAds i keep getting this error. "could not cast value of type 'UIView' (0x196afa530) to 'SKView' (0x19685f560)." this is the code that fails and the code on the bottom is my inter view controller code.. which is not much. i think at also has something to do with this code for iAds. var interstitialAdView: UIView = UIView() Code: override func viewWillLayoutSubviews() { super.viewWillLayoutSubviews() if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {

Receive touch events at SKScene AND SKSpriteNode in SpriteKit

别等时光非礼了梦想. 提交于 2019-12-11 12:55:06
问题 Building a UI with buttons as SKSpriteNode's. Button sprites receive touch events to handle special effects (elastic scaling effects) But I need the SKScene to handle the touch events at the same time to handle UI navigation logic. How would be possible to both (sprite AND scene) to handle these touch events? 来源: https://stackoverflow.com/questions/34987142/receive-touch-events-at-skscene-and-skspritenode-in-spritekit

Can you save the position of a node in an sks file

烂漫一生 提交于 2019-12-11 08:08:52
问题 I'm trying to create a SKScene file where we create empty nodes at the places where our players and other objects will be placed. The problem is that the positions all have to be set in code. Is it possible to set the position in the sks file instead? I did notice there is a Position label in the node inspector, but that doesn't appear to have any effect. 回答1: Write data with NSUserDefaults: NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSDictionary *nodeDict = [