skspritenode

Handling Multiple GestureRecognizers

帅比萌擦擦* 提交于 2019-12-12 08:44:47
问题 I've run into an issue understanding UIGestureRecognizers . My goal right now is to have a set of GestureRecognizers to do different tasks, for example: override func viewDidLoad() { mainScene = GameScene(size: self.view.bounds.size) main = view as! SKView mainScene.panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(shiftView(recognizer:))) main.addGestureRecognizer(mainScene.panRecognizer) mainScene.tapRecognizer = UITapGestureRecognizer(target: self, action: #selector

How to bring a SKSpriteNode to front?

怎甘沉沦 提交于 2019-12-12 07:24:34
问题 How can I bring a SKSpriteNode to the front of all other node? With UIView, I can use bringSubviewToFront to bring an uiview in front of other views. 回答1: You can't "bring it to front" but you can change the zPosition of it. The higher the zPosition of the node the later it gets rendered. So if you have three nodes with zPositions of -1, 0 and 1 then the -1 will appear at the back. Then the 0. Then 1 will appear at the front. If they all use the default zPosition of 0.0 then they are rendered

How to instantiate SKSpriteNode spritekit swift 3

瘦欲@ 提交于 2019-12-12 06:59:33
问题 I have a 2 player space shooter game and am having trouble with the shooting part. I currently have a ship that moves it's x position with your finger. I want it to shoot strait up when the user pushes the "fire" button. So here is my question. How can I instantiate my bullet(SKSpriteNode) at the gun tip and shoot upwards when the user pushes the "fire"? 回答1: This is pretty basic but you need to: Create a new sprite for the bullet Position the bullet in the same place as the ship Make the

How to have Billiards like physics in SpriteKit?

筅森魡賤 提交于 2019-12-12 04:23:30
问题 I'm new to SpriteKit and am trying to make a Billiards game but it just doesn't seem to be working properly. The balls don't bounce off each other or the pool cue. I'm not sure what I'm doing wrong. Here is some sample code of one of the balls and the pool cue. Any help will be appreciated! class PoolTableScene: SKScene, SKPhysicsContactDelegate { struct PhysicsCatagory { static let None : UInt32 = 0 //0 static let PokeBall : UInt32 = 0b1 //1 static let PoolCue : UInt32 = 0b1000 //5 static

Incompatible block pointer SKSpriteNode

笑着哭i 提交于 2019-12-12 04:18:46
问题 This is my code - (void) update:(NSTimeInterval)currentTime { [self.children enumerateObjectsUsingBlock:^(SKSpriteNode * child, NSUInteger idx, BOOL *stop) { child.position = CGPointMake(child.position.x-self.scrollingSpeed, child.position.y); if (child.position.x <= -child.size.width){ float delta = child.position.x+child.size.width; child.position = CGPointMake(child.size.width*(self.children.count-1)+delta, child.position.y); } }]; } And i am getting an an error Incompatible block pointer

How to make a node visible before any user interaction

℡╲_俬逩灬. 提交于 2019-12-12 03:21:49
问题 I took and modified a piece of code which allows me to shoot bullets in every direction. It works perfectly. But it is generating a random bullet in the moment when player touch is ended. I have 6 different bullets and for purposes of my game I need player to see them before he will tap the screen. I tried to initialize a bullet in a global function and pass it to didMoveToView. It's not working, bullet is generating once and stays at its place. That is my code for initializing a bullet:

SKShapeNode Using Wrong Width and Height

爷,独闯天下 提交于 2019-12-12 03:15:42
问题 Recently I have been creating a game where I put circles on the screen. However, I noticed that the circulars were not circles, but in fact ovals. The y axis had been stretched of the x axis had been shrunk. In order to figure out the issue, I am now trying to debug with a rectangle. I made the rectangle have the same height and width (square) however, when turned into an skshapenode it is no longer the correct shape. The code: var testSquare = CGRect(x: CGRectGetMidX(self.frame), y:

Sprite-kit Main Character Picker

不想你离开。 提交于 2019-12-12 03:11:37
问题 I am using swift 2 and sprite-kit. I was wondering how I would make a choose character scene for my player to choose a character to play in the game, I have the scene set up, but I don't know how to integrate multiple characters, that can be chosen as the one to play? Any references or sample code would be appreciated. in GameScene() i have //plane = SKSpriteNode(imageNamed: "plane") plane.size = CGSize(width: 80, height: 80) plane.position = CGPoint(x: self.frame.width / 2, y: self.frame

SKTexture from UIImage looks different

橙三吉。 提交于 2019-12-12 01:13:18
问题 I'm playing around with SpriteKit and I'm creating a SKTexture from an UIImage, then using SKSpriteNode to add the child to my SKScene (As a background), everything works fine, except that the UIImage looks very different from the original image, I tried to recreate the image in photoshop and the issue still remains, tested on Simulator and real device and different image colors, no changes. The image format is PNG, and I added through Images.xcassets in Xcode 5 Image, results: Different

Ellipse SKPhysicsBody

跟風遠走 提交于 2019-12-12 01:07:13
问题 Which SKPhysicsBody body type would I use to create an elliptical physicsBody? I know I could make a curve out of straight lines and just have it not be a real ellipse, but it seems like there must be some way to squish a circle or create one? 回答1: Create an elliptical CGPath and create a polygon body with that path: CGPathRef path = CGPathRef CGPathCreateWithEllipseInRect(someRect, nil); SKPhysicsBody* body = [SKPhysicsBody bodyWithPolygonFromPath:path]; It's possible though that the created