sprite-kit

creating buttons in skview to point to different scenes

烈酒焚心 提交于 2019-12-08 04:13:32
问题 i am trying the sprite kit for the first time. just to state the obvious, I've been through the doc's but i can't quiet grasp the idea of creating multiple buttons yet. i can create the buttons alright. and they appear in my view, but i can't attach the function to them in order to point to different views. here is the code I'm using for creating the buttons and so on: #import "Levels.h" #import "MyScene.h" #import "MyScene1.h" @interface Levels () @property BOOL contentCreated; @end

Does adding new action for the scene remove automatically the one before in SpriteKit?

孤街浪徒 提交于 2019-12-08 04:09:22
问题 I want to know if I made a sequence action and while this sequence is running a new action added to the scene , Does the new action stop the sequence ? If yes , how i can make both of them working if the new action is added in swift ? 回答1: The only time a new action will interfere with any running actions is if both actions share the same key. If you do not assign a key, then every time you add an action, it gets added to the action pool and will run concurrently. 回答2: If you just give it a

Call function on app termination in Swift

落爺英雄遲暮 提交于 2019-12-08 03:59:53
问题 How can I call a function that is within an SKScene class when my app is terminated by the user? I need to modify a value and save it to NSUserDefauts when the app is terminated. 回答1: You can register to receive a notification when your app is about to terminate. To do this, add an observer to the default notification center by // Add this to didMoveToView in your SKScene subclass NotificationCenter.default.addObserver(self, selector: #selector(saveData), name: NSNotification.Name

What's the cleanest way to call a method from one SKScene to another in Swift?

萝らか妹 提交于 2019-12-08 03:51:17
问题 So I got in my game 3 different scenes: MenuScene, GameScene and GameOverScene. I would like to know how I can get the score variable located in GameScene from GameOverScene so I can show it up there after the player loses. So in GameScene, I created this simple getter: func getScore() -> Int { return self.score } But if I try to do GameScene.getScore() from a different Scene I get an error. Tried using "class" before func class func getScore() -> Int { return self.score } But that also gives

Ball bouncing off the wall doesn't work

偶尔善良 提交于 2019-12-08 03:36:49
问题 I am trying to let the ball bounce back when it is about to go off the screen. I thought it should work with this: bal.physicsBody?.velocity.dx = -bal.physicsBody?.velocity.dx but it doesn't.. I am getting this error: Could not find an overload for "-" that accepts the suplied arguments. How to solve this? 回答1: You could do either: if let physicsBody = bal.physicsBody { physicsBody.velocity.dx *= -1 } Or bal.physicsBody?.velocity.dx *= -1 Or, if you're absolutely certain bal has a physics

Spritekit iAds messing with scene size

∥☆過路亽.° 提交于 2019-12-08 03:15:20
问题 I am making a game using spritekit and everything works perfectly except when I add the code to add an iAd. When I add the iAd everything works but it seems that the iAd is resizing the scene when it is being displayed. This is my code to display the iAd, it is in the ViewController.m : #import <iAd/iAd.h> #import "ViewController.h" #import "MainMenu.h" @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Configure the view. SKView * skView = (SKView *)self

Touch Sprite, make it jump up then fall down again(repeat as many times as spritenode is tapped.)

北战南征 提交于 2019-12-08 03:15:04
问题 I created a project where I have a ball and when the view loads, it falls down, which is good. I'm trying to get the ball to jump back up and fall down again when the Spritenode is tapped. --This Question was edited-- Originally, I was able to get it to work when sprite.userInteractionEnabled = false . I had to turn this statement true in order to get the score to change. Now I can't get the balls to fall and be tapped to jump. When I turn ball.physicsBody?.dynamic = true , the balls will

SKAction.playSoundFileNamed not working in iOS 9

血红的双手。 提交于 2019-12-08 02:55:44
问题 I think I've got my game working almost the same as it was before iOS 9 came along... I have included the entire function, but the only thing I am having a problem with is the sound effect at the beginning of the function: func collisionHappened() { let bangSoundEffect = SKAction.playSoundFileNamed("Bang.mp3", waitForCompletion: false) runAction(bangSoundEffect) //nothing happens here let defaults = NSUserDefaults() let highscore = defaults.integerForKey("highscore") if (score > highscore){

How to reverse the direction of path followed by sprite in an SKAction midway?

爱⌒轻易说出口 提交于 2019-12-08 02:47:38
问题 I have a SKSpriteNode which is moving along a circular path using an SKAction : // create the path our sprite will travel along let circlePath = CGPathCreateWithEllipseInRect(CGRect(origin: pathCenterPoint, size: CGSize(width: circleDiameter, height: circleDiameter)), nil) // create a followPath action for our sprite let followCirclePath = SKAction.followPath(circlePath, asOffset: false, orientToPath: false, duration: 2 I can add .ReversedAction() to reverse the direction of the sprite, but

SpriteKit and UIKit compatibility: OpenGL error when migrating to Swift 2?

匆匆过客 提交于 2019-12-08 02:45:00
问题 I just don't understand what is going on since I migrated to Swift 2. I have a Tabbed application and I am getting this error: <CAEAGLLayer: 0x7fb2e053fb40>: calling -display has no effect. Assertion failed: (length + offset <= _length), function commit_data, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/Jet_Sim/Jet-1.50/Jet/jet_types_OpenGL.h, line 863. I know it is really vague but I don't know where to start looking for bugs. Thanks. Edit: I just realized it might be related to the