sprite-kit

Error spawning sprites in Swift/SpriteKit

房东的猫 提交于 2020-01-17 05:49:46
问题 I'm having a problem in my code. When my obstacles come down forever, the "path" where the square is supposed to go through is sometime off the screen, and not positioned where I want it. I want the path to be between 1/4 of the screen width. I think the error is somewhere in the width and randomXPos constants. How can I fix this? (If you want a further explanation I can explain more.) func addObstacles2() { let obstacle2A = SKSpriteNode(imageNamed: "Obstacle") let obstacle2B = SKSpriteNode

Could not cast value of type 'UIView' (0x1102beb40) to 'SKView' (0x10f0814c8)

只愿长相守 提交于 2020-01-17 05:19:14
问题 Im trying to programmatically switch from a UITableView to a SKView (Can't use the storyboard to place buttons on a TableView). This is the code a have to switch views: ViewController.swift : func game() { let game = GameViewController() present(game, animated: true, completion: nil) } GameViewController.swift : import UIKit import SpriteKit class GameViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() if let scene = GameScene(fileNamed:"GameScene") { //

How to change the default SKScene that displays on startup

房东的猫 提交于 2020-01-17 05:06:16
问题 I've been developing a game that has been done in the single default GameScene created by XCode. Now I want to add more screens including a title screen that displays before the GameScene does and a 'Game Over' scene. The game over scene is transitioned from the GameScene and back and works fine but I cant get the title screen to display despite altering the code in GameViewController.swift: class GameViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() /

iAd banner unpauses spritekit game

安稳与你 提交于 2020-01-17 04:23:47
问题 I am developing an iOS game using sprite kit with an iAd banner, and this iAd is causing the game to unpause itself, and by unpausing I mean SKActions are continuing, here are some details: 1) I have several objects in my game that have a sequence (in series not parallel) of SKActions. 2) clicking the 'pause game' button on my game's screen and 'resuming' work fine - everything is pauses as desired. NSLog statement in "Note" below not displayed. 3) I've coded the following notification which

iAd banner unpauses spritekit game

蹲街弑〆低调 提交于 2020-01-17 04:23:07
问题 I am developing an iOS game using sprite kit with an iAd banner, and this iAd is causing the game to unpause itself, and by unpausing I mean SKActions are continuing, here are some details: 1) I have several objects in my game that have a sequence (in series not parallel) of SKActions. 2) clicking the 'pause game' button on my game's screen and 'resuming' work fine - everything is pauses as desired. NSLog statement in "Note" below not displayed. 3) I've coded the following notification which

SpriteKit scene with low fps on start

主宰稳场 提交于 2020-01-17 03:41:26
问题 My problem is that my GameScene starts with about double the nodes and draws count and 40 fps for several seconds. This problem appears only on my iPad (mini retina) while on my iPhone (5) the game runs smoothly from the start although the nodes are still a lot more than what it should be 回答1: This 40fps problem is an issue within the iOS frameworks. It's created by some kind of throttling (by iOS). Perhaps this throttling was designed to give a more consistent experience for an app

Converting tiles to sprite nodes in XCode Swift

我们两清 提交于 2020-01-17 03:37:22
问题 I am developing a mini-game and I've drawn the map by using the program Tiled. Let's assume that I've used a tile set of three pictures; how do I 'convert' them to SKSpriteNodes? Let's say that there is one tile representing the character and three tiles representing ground. I want these four to be sprite nodes. Thanks in advance 回答1: I can't help you with the Swift version but look at the below pics to get a better understanding of what I am talking about. Create an Object Layer in Tiled.

Get a list of all SpriteKit Scenes in App Bundle

浪子不回头ぞ 提交于 2020-01-16 19:24:48
问题 As a followup to this question, I need to iterate over each .sks file in a folder, namely, "Levels". My project looks like this: Here's what I've written: let directory = NSFileManager.defaultManager().currentDirectoryPath let paths = NSBundle.mainBundle().pathsForResourcesOfType("sks", inDirectory: directory) let files = paths.map() { (path : AnyObject) -> String in return (path as String).lastPathComponent } println("Files\n\(files)") let firstLevel = files[0] if let scene = SKScene

SKSpriteNode using PDF/SVG Vector Image for automatic scaling

醉酒当歌 提交于 2020-01-16 12:18:06
问题 I'm trying to use a PDF/SVG Image as the SKTexture for an SKSpriteNode. I know that this can be done for a UIImageView by ticking "Preserve Vector Data", setting Scaled to "Single Scale" and configuring the UIImageView to imageView.adjustsImageSizeForAccessibilityContentSizeCategory = true Is this possible to do when using the UIImage in an SKTexture? This would prevent the creation of @2x & @3x images. Thanks 回答1: You cannot use vector images for an SKTexture A SKTexture doesn't have a

Receiving an error when nodes make contact

痞子三分冷 提交于 2020-01-16 09:07:33
问题 I am currently making a game in which you are a space ship in the middle and there are enemy ships moving towards you and you have to shoot at them to win. While I was testing the game I saw that I received an error when (it appears to be) two or more enemy ships hit the player ship at the same time. I am not certain if this is what's causing the error but it looks like it when I test it. I made the game so that whenever enemy players touch the player, the game ends and a function is called