sprite-kit

In Swift on “game over” move from scene to another UIView and dispose the scene?

孤街醉人 提交于 2019-12-25 04:36:19
问题 I have a "life counter" in my game and when it hits 0 = dead - i want to move away from the scene to another UIView - which is game over view - with stats and a button to go back to the home screen (first UIViewController with buttons to start the game and so on. Here is the code of how i move to the Game Over view class GameScene: SKScene,SKPhysicsContactDelegate { var viewController: UIViewController? // more code and functions // ...... func trackLife (lifeCHange: Int){ life = life +

How to put GameCenter on application with swift?

孤街醉人 提交于 2019-12-25 04:28:07
问题 I made a game using SpriteKit and Xcode 7 beta. I tried to add GameCenter and Leaderboard but the problem is that the score in the leaderboard won't change (HighScore doesn't upload to GameCenter), It stay 0 all the time and I don't know how to fix it. I'm using 2 different files: GameViewController.swift, and PointsLabel.swift GameViewController.swift: import GameKit class GameViewController: UIViewController,UIGestureRecognizerDelegate, GKGameCenterControllerDelegate { var score:

How to put GameCenter on application with swift?

。_饼干妹妹 提交于 2019-12-25 04:28:01
问题 I made a game using SpriteKit and Xcode 7 beta. I tried to add GameCenter and Leaderboard but the problem is that the score in the leaderboard won't change (HighScore doesn't upload to GameCenter), It stay 0 all the time and I don't know how to fix it. I'm using 2 different files: GameViewController.swift, and PointsLabel.swift GameViewController.swift: import GameKit class GameViewController: UIViewController,UIGestureRecognizerDelegate, GKGameCenterControllerDelegate { var score:

Lag / Delay on ModalViewController dismiss after loading an xib view over SKView

你说的曾经没有我的故事 提交于 2019-12-25 04:06:55
问题 Imagine this scenario (some code below): I have an SKView on a viewcontroller. I load an xib view (external .xib file) over skview (xib view is a like small menu view that does not cover screen in full). Then, I show a view controller modally from SKView's controller When I dismiss this modal view controller, there is a lag on every second dismissal (so, i show it modally, dismiss, it is fine, then i repeat, there is delay, then repeat, works fine, then do again, there is delay ... and so on)

SKTextureAtlas - Pass in a path to an atlas instead of looking for that specific atlas

匆匆过客 提交于 2019-12-25 03:39:20
问题 I'm working on a class to handle character animations. The animations will have different skin tones that the user chooses from in character creation. The atlases for each of the skin tones have the same name but are stored in differently named folders like this: this is in the xcassets folder This should allow my code to be more modular so I don't have to hard-code a ton of stuff. I want my code to locate the chosen skin tone folder and its subdirectories so that the correct animation plays

How do I add a score system to this Spritekit game?

99封情书 提交于 2019-12-25 03:35:30
问题 I can't figure out a way to add a score system to my game. Can someone please help me do this in a visual, GUI way? Thanks very much. I have tried doing this with an int variable, but it won't work. If you do help, again, thank you very much import SpriteKit let BallCategoryName = "ball" let PaddleCategoryName = "paddle" let BlockCategoryName = "block" let BlockNodeCategoryName = "blockNode" let BallCategory : UInt32 = 0x1 << 0 // 00000000000000000000000000000001 let BottomCategory : UInt32 =

Drawing straight line with spritekit and UITouch creates multiple lines

拈花ヽ惹草 提交于 2019-12-25 03:07:55
问题 Should be simple. I'm trying to draw a single, straight line using UITouch and Spritekit. However, when touchesmoved is called, it creates multiple lines instead of just a single line. Code used is below: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; positionInScene1 = [touch locationInNode:self]; pathToDraw = CGPathCreateMutable(); selectorLine = [SKShapeNode node]; selectorLine.strokeColor = [SKColor greenColor]; selectorLine

Swift: Progress bar jumps when using showing progress

↘锁芯ラ 提交于 2019-12-25 02:57:16
问题 The code below works if the background and the progress bar share the same dimensions. If the progress bar is shorter, the bar jumps around a bit whenever there is an update -- as if scaling the progress bar changes the origin for the progress bar. What's the right way to implement custom progress bars in Swift and SpriteKit? private func initProgressLayer(gridLeftX: CGFloat, gridWidth: CGFloat) { // Set progress bar width var progressWidth = gridWidth let barWidth = CGFloat(50) let barHeight

Sprite Kit - Detecting Y due to an impulse and Gravity, if the ball is moving away or Closer to the ground

吃可爱长大的小学妹 提交于 2019-12-25 02:47:53
问题 I'm creating a false shadow for an SKSpriteNode (a Ball) with physicsBody and impulse in Y direction applied to it. I like to decrease the opacity of the shadow which stays on the ground as the ball raise and decrease it back to 100% as it heads back toward the ground. any Idea? 回答1: Yes, use the update method. Then simply test the balls Y position on every update. Add the ball to your scene. Add a shadow to your scene. In the update method of your scene (called at every frame by SpriteKit)

touchesMoved on a specific moving object

一笑奈何 提交于 2019-12-25 02:45:09
问题 Im using Spritekit to create a game for iOS 7. The game has circles moving across the screen using this code _enemy = [SKSpriteNode spriteNodeWithImageNamed:@"greeny"]; _enemy.position = CGPointMake(CGRectGetMidX(self.frame)+300, CGRectGetMidY(self.frame)); _enemy.size = CGSizeMake(70, 70); _enemy.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:35]; _enemy.physicsBody.mass = 0; _enemy.physicsBody.categoryBitMask = Collisiongreen; [_enemies addObject:_enemy]; NSLog(@"Enemies%lu",(unsigned