sprite-kit

Swift3: UISwipeGestureRecognizer in only one of putatively many SKViews

回眸只為那壹抹淺笑 提交于 2019-12-24 10:54:17
问题 Note: Prior to asking this question I have viewed and attempted solutions posted for the following questions: gesture recognizer with sprite kit and swift Swift3 iOS - How to make UITapGestureRecognizer trigger function how to add a gesture to skView? using UIGestureRecognizer with Swift Context: I have implemented a basic game menu for my game following the example set here. When I reach the GameScene I would like to have a UIGestureRecognizer that when the screen is swiped up, opens a pause

How to run or execute an SKAction from outside of the object?

荒凉一梦 提交于 2019-12-24 08:58:29
问题 I have some code like following: -(void) createBall { _ballSprite = [SKSpriteNode spriteNodeWithImageNamed:@"ball0001"]; _ballSprite.position = CGPointMake(firstNode.position.x, firstNode.position.y); SKAction *ballScale =[SKAction scaleXTo:-0.5 duration:0]; SKAction *ballMove = [SKAction moveByX:0 y:-300 duration:0]; SKAction *ballMoveScale = [SKAction sequence:@[ballScale,ballMove]; SKAction *ballScaleMove = [SKAction sequence:@[ballMove,ballScale]; //Unused variable [_ballSprite runAction

Load a spritekit scene from another bundle?

折月煮酒 提交于 2019-12-24 08:50:03
问题 I am making a SpriteKit framework using swift 4.2 and want to include some .sks files for scenes and actions. I have tried to load the scene from the bundle using the code below: class func newGameScene() -> GameScene { guard let gameScenePath = Bundle(for: self).path(forResource: "GameScene", ofType: "sks") else { assert(false) } guard let gameSceneData = FileManager.default.contents(atPath: gameScenePath) else { assert(false) } let gameSceneCoder = NSKeyedUnarchiver(forReadingWith:

Issues with batch drawing with atlas files and SpriteKit

北城余情 提交于 2019-12-24 08:41:33
问题 So I ran into a problem with lag on a platformer game I'm building. So I'm researching how to improve performance. I'm trying to do batch drawing, so that there is less draw calls. I'm having issues though. So with a brand new project: I have 4 hero sprites, all images are stored in a .atlas folder. so there is a 1/2/3x image for each sprite in the atlas folder. I drag and drop that into the xcassets folder. Then I go to my sks file create 4 sprites and change the texture accordingly. By

Private Boolean: how to set on SKCropNode, with Swift?

六月ゝ 毕业季﹏ 提交于 2019-12-24 08:12:26
问题 SKCropNode works by removing every thing from its affected nodes that are not covered by its source image. This is one type of masking, the other is to invert this logic, and reveal everything that's not covered by the source image. SKCropNode has a boolean switch to set this state, called invertMask , sensibly enough. What's annoying is that it's seemingly private. If putting aside all the app store approval processes, dangers of private APIs, etc, and accepting that it's something

SKPhysicsBody from Texture gives null on collision in Spritekit

别来无恙 提交于 2019-12-24 07:39:35
问题 I am creating a game where character jumps and collect points (SOME OBJECT). When you tap character perform some animation from atlas. When it touches the points, score is increased by 1. I am using SKTexture to create physicbody of the character. When my character touches the point it crashes and show me this error fatal error: unexpectedly found nil while unwrapping an Optional value //Code Cat = SKSpriteNode(imageNamed: "cat"); Cat.size = CGSize(width: 100, height: 100) Cat.position =

Align SpriteNode with surface on collision SpriteKit Swift3

随声附和 提交于 2019-12-24 07:30:13
问题 Im trying to align a SKSpriteNode to match the "hit surface" of a PhysicsBody on collision. What I'm doing is to shoot the SpriteNode at a Cube. I have setup the collision and the node attachment (fixed joint). Everything works but I need to find a way to rotate the spriteNode to match the hit surface as you can see below: Note that the Cube can rotate etc so we don't always have a fixed rotation value on the Cube. Any Ideas how to solve this? Thanks in advance /Magnus 回答1: Here is most of

How to properly get a gesture recognizer to fluidly spin a sprite according to velocity

五迷三道 提交于 2019-12-24 07:13:19
问题 I've a Sprite that animates via texture array, with spinLeft being increasing the array index, and spinRight decreasing the index, as shown in the answer to my other question here: https://stackoverflow.com/a/44792902/6593818 The animation is working fine, but now I am trying to control the animation via a gesture recognizer or some other form of input. In the referenced question, the spin function has an input for speed (the TimeInterval), so I just need an output from a gesture recognizer:

Character falling through ground

隐身守侯 提交于 2019-12-24 07:04:27
问题 I'm using sprite kit as a part of a basic game. The game is that there is a guy who, depending on where you tap, moves to that location. Currently, the player is not affected by gravity (for the sake of playibility) but I'm trying to implement gravity. However, when I do turn gravity on for the player, I'm having trouble with my character falling through the ground. I've created a node for the ground and have disabled the ground physics (ground.physicsBody.dynamic = NO) but the character

Call GameScene method from AppDelegate (Swift 3, SpriteKit, Xcode 8)

与世无争的帅哥 提交于 2019-12-24 06:48:56
问题 I am using Spritekit and swift 3 for create a game, my problem is when I try to call my pauseGame() method, present in my GameScene class (subclass of SKScene), from AppDelegate file within applicationWillResignActive(_ application: UIApplication) method. I already try to instantiate GameScene class and then call the method in my AppDelegate file in this way, although there is no compiler error it doesn't work: func applicationWillResignActive(_ application: UIApplication) { if let gameScene