sprite-kit

How to use the SpriteKit method body(at : CGPoint)?

半城伤御伤魂 提交于 2020-01-23 13:04:14
问题 I have game that during the game your finger moves around and should avoid hitting some obstacles. I know how to use collision but I recently heard that there is a funtion called the body(at : point) . I should say that I have masked my obstacles. Because of that I can't use the contains(point) function. I really want to use the body(at : point) function otherwise I know how to work with collisions. Some of my code: play_button = self.childNode(withName: "play_button") as! SKSpriteNode for t

Can't add custom font to Xcode

旧时模样 提交于 2020-01-23 12:34:48
问题 I'm trying to add a downloaded font to Xcode and I've folowed every single step based on this link: http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/ I added the font to my Xcode Project, included it in Copy Bundle Resources (Build Phases), and typed it in Fonts Provided by Application (in Info.plist). Then I typed this in GameScene.swift inside didMoveToView It has worked with other fonts but not with this one. This is really frustrating me and I've got no

Can't add custom font to Xcode

女生的网名这么多〃 提交于 2020-01-23 12:34:10
问题 I'm trying to add a downloaded font to Xcode and I've folowed every single step based on this link: http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/ I added the font to my Xcode Project, included it in Copy Bundle Resources (Build Phases), and typed it in Fonts Provided by Application (in Info.plist). Then I typed this in GameScene.swift inside didMoveToView It has worked with other fonts but not with this one. This is really frustrating me and I've got no

TouchEvents in watchOS 3 SpriteKit?

a 夏天 提交于 2020-01-23 07:41:35
问题 When using SpriteKit in watchOS 3, how do you handle the touch events? I am porting the SpriteKit games from iOS and the codes below won't work. Or you have to control the WKInterfaceController somehow? override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {} override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {} override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {} override func touchesEnded(_ touches: Set<UITouch>, with

TouchEvents in watchOS 3 SpriteKit?

落爺英雄遲暮 提交于 2020-01-23 07:41:34
问题 When using SpriteKit in watchOS 3, how do you handle the touch events? I am porting the SpriteKit games from iOS and the codes below won't work. Or you have to control the WKInterfaceController somehow? override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {} override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {} override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {} override func touchesEnded(_ touches: Set<UITouch>, with

SpriteKit memory management preload cached and fps issue

旧城冷巷雨未停 提交于 2020-01-22 11:58:44
问题 My question is pretty simple, according to the apple docs you have the ability to preload textures into RAM prior to presenting a scene like so: SKTextureAtlas * atlas = [SKTextureAtlas atlasNamed:@"effect_circle_explode"]; SKTextureAtlas * atlas2 = [SKTextureAtlas atlasNamed:@"box_explodes"]; SKTextureAtlas * atlas3 = [SKTextureAtlas atlasNamed:@"fence_new"]; SKTextureAtlas * atlas4 = [SKTextureAtlas atlasNamed:@"swipe"]; SKTextureAtlas * atlas5 = [SKTextureAtlas atlasNamed:@"coin"];

Swift : Background Color fading animation (SpriteKit)

末鹿安然 提交于 2020-01-21 09:42:06
问题 I'm creating a game, the background color is white to begin with hence: self.backgroundColor = SKColor.whiteColor() So when the game initiates white is the background. I have a scoring system, so essentially I want the colors to change when a certain score is reached hence: if score < 100{ enemy.runAction(SKAction.moveTo(mainBall.position, duration:3)) } else if score >= 100 && score < 200{ enemy.runAction(SKAction.moveTo(mainBall.position, duration:2.5)) self.backgroundColor = SKColor

How to change center of gravity in sprite kit game?

不问归期 提交于 2020-01-21 08:36:46
问题 I have been trying to find, but did not succeed. Is there a way to change physicsworld gravity property in such way, that objects would not be attracted towards the bottom of the screen, but to the centre of it instead? 回答1: Use an SKFieldNode for that. Just place it at the center of your map and disable gravity by putting code in that sets the gravity to zero ( CGVector(0,0) ) I would give you code, but I don't use Objective C, so I don't know the exact syntax for it. I can give it a shot

Swift - How to remove swipe gesture from scene when moving to another one?

孤街醉人 提交于 2020-01-21 03:46:25
问题 So my game uses swipe gestures, in my didMoveToView() function I have these gestures initialized: let swipeRight = UISwipeGestureRecognizer() swipeRight.direction = UISwipeGestureRecognizerDirection.Right self.view?.addGestureRecognizer(swipeRight) let swipeLeft = UISwipeGestureRecognizer() swipeLeft.direction = UISwipeGestureRecognizerDirection.Left self.view?.addGestureRecognizer(swipeLeft) let swipeUp = UISwipeGestureRecognizer() swipeUp.direction = UISwipeGestureRecognizerDirection.Up

ios - Spritekit - How to calculate the distance between two nodes?

感情迁移 提交于 2020-01-20 02:23:14
问题 I have two sknodes on the screen. What is the best way to calculate the distance ('as the crow flies' type of distance, I don't need a vector etc)? I've had a google and search on here and can't find something that covers this (there aren't too many threads on stackoverflow about sprite kit) 回答1: Here's a function that will do it for you. This is from an Apple's Adventure example code: CGFloat SDistanceBetweenPoints(CGPoint first, CGPoint second) { return hypotf(second.x - first.x, second.y -