sprite-kit

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

不打扰是莪最后的温柔 提交于 2019-12-06 15:02:41
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 me an error from GameScene saying: "Instance member 'score' cannot be used on type GameScene" So how's

SpriteKit - Mouse Snaps to Center On Sprite Drag

吃可爱长大的小学妹 提交于 2019-12-06 14:51:04
I'm trying to create an iOS game and I have it so that when the item is touched and moved it is dragged. When it is dragged the mouse is snapped to the center of the sprite. How could I make it so that this wouldn't happen? Here is an example of what is happening. Here are the functions dealing with touch input override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { var papers = 0 for touch in (touches as! Set<UITouch>) { let location = touch.locationInNode(self) let touchedNode = nodeAtPoint(location) if ((touchedNode.name?.contains("paper")) != nil) { touchedNode

SCNScene: Calculate projected size of an object

空扰寡人 提交于 2019-12-06 14:23:27
问题 My game has a scene and HUD (SKScene) as in most games. To avoid overlap with HUD elements, I need to calculate the projected size of my main object. Because the HUD dimensions and projected size of the object are different for each iPhone model, I need a way to do this dynamically, and for that I need to get the projected size of my main object. The obvious approach for me was to use the xFov and yFov, but for some reason they are always zero. usesOrthographicProjection is set to false so it

Pause NSTimer on home-button-press and start them again once the app is in foreground

社会主义新天地 提交于 2019-12-06 14:20:06
I've been searching for a solution to pause my SpriteKit game when the user "tabs down" the game. So far I found a solution where you use SKAction 's instead of NSTimer 's, this works as long as the time between actions stays the same. However, my NSTimer 's changes in speed. So I need to find another solution. I have a bunch of NSTimer 's located in GameScene -> didMoveToView NSTimer.scheduledTimerWithTimeInterval(0.2, target: self, selector: Selector("SpawnBullets"), userInfo: nil, repeats: true) NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: Selector("SpawnMeteors"),

How to show iAd on a certain SKScene and hide it on the other one

妖精的绣舞 提交于 2019-12-06 13:49:36
I'm making a simple game and I would like to add an iAd at the top of the Game Over Screen. I could add it on to the UIViewController , but then it would show up while playing, which is something I don't want. Is there a way to make the iAd appear only on a certain SKScene ? Thanks for all your help! The most clean solution is to declare and implement a protocol to let the UIViewController know that it should hide the ad. @protocol MySceneDelegate <NSObject> - (void)hideAd; - (void)showAd; @end @interface MyScene : SKScene @property (weak) id <MySceneDelegate> delegate; @end View controller

SKshapenode is not responding to Physicsbody

风流意气都作罢 提交于 2019-12-06 13:44:30
I have created a SKShapeNode and I have assigned a physicsBody to it. However, it is not being triggered when there is contact. Creation of SKShapeNode code: -(SKShapeNode*)gravityline{ //SKSpriteNode *lolo=[[SKSpriteNode alloc]init]; SKShapeNode *lolo = [[SKShapeNode alloc] init]; CGPoint fff=CGPointMake(ray1.position.x, ray1.position.y); CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, NULL, fff.x, fff.y); CGPathAddLineToPoint(path, 0,rayoriginpoint.x,rayoriginpoint.y ); CGPathCloseSubpath(path); lolo.path = path; lolo.name=@"gravityline"; lolo.strokeColor=[SKColor

Present an UIAlertController with a SpriteKit scene (Objective-C)

半城伤御伤魂 提交于 2019-12-06 13:33:54
I'm trying to make a SpriteKit app that has a button to go to my website if the user so desires to. I thought it would be a good practice to make an alert (since it's made for iOS 8, I'd use a UIAlertController ) confirming if they want to be redirected to Safari to see it. Here's what I have in code for the method to make/present this alert so far: UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Go to website" message:@"Would you like to visit DannyDalton.com? This will open Safari." preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *yes =

Visual Studio for Mac: Guid should contain 32 digits with 4 dashes (xxxx…)

倖福魔咒の 提交于 2019-12-06 13:20:17
问题 I'm a noob for Visual Studio for Mac. My intention was to check out Xamarin development. My Visual Studio version is 7.3 (Build 799) Community Edition, I've installed on a MB Pro 2015 Mid model. When I try to create a project in following way, Multiplatform App Games (iOS, Mac) SpriteKit Game (2D) And then proceeded with the steps until pressing the create button giving project name and all it just gives me the following Alert and I cannot create the project. Updated: I found following Log by

Modify a repeating task sequence while running

北慕城南 提交于 2019-12-06 12:54:31
问题 I am trying to make a repeating task where I can change the delay in which it repeats. Here is the current code I am using: var actionwait = SKAction.waitForDuration(self.wait) var actionrun = SKAction.runBlock({ self.count+=1 if (self.count % 2 == 0 && self.wait > 0.2){ self.wait -= 0.1 actionwait.duration = self.wait } for node in self.children{ if (node.isMemberOfClass(Dot)){ node.removeFromParent() } } var radius = CGFloat(arc4random_uniform(100) + 30) var newNode = Dot(circleOfRadius:

Change SKScene using presentScene()

…衆ロ難τιáo~ 提交于 2019-12-06 12:54:29
In my SpriteKit Game i'm using: self.scene!.removeFromParent() let skView = self.view! as SKView skView.ignoresSiblingOrder = true var scene: PlayScene! scene = PlayScene(size: skView.bounds.size) scene.scaleMode = .AspectFill skView.presentScene(scene, transition: SKTransition.fadeWithColor(SKColor(red: 25.0/255.0, green: 55.0/255.0, blue: 12.0/255.0, alpha: 1), duration: 1.0)) to move from one scene to another. But how can I go back to the original scene? Using the same principle of code always led to a major crash.. Whirlwind I made an example where global structure is used to track the