sprite-kit

How to create triangle in SpriteKit (Swift 2)

梦想的初衷 提交于 2019-12-13 08:53:40
问题 I did it with SKSpritenode func AddTopTriangels() { TopTriangel = SKSpriteNode(imageNamed:"Top-Triangels.png") TopTriangel.position = CGPointMake(frame.size.width/2, frame.size.height/2 + 370) TopTriangel.size = CGSize.init(width: 440, height: 35) addChild(TopTriangel) } But i want to create it with SKShapenode , how i can do it? 回答1: You should create SKSpriteNode as you did in the question and just attach physic body to it with triangle shape: var trianglePath = CGPathCreateMutable()

move a background endless in swift 4

空扰寡人 提交于 2019-12-13 08:25:54
问题 Hi i'm trying to move a background endlessly, but i have a little problem when i simulate the code. This is my code didMove(to view: SKView) { for i in 0...1 { let backgroundNEW = SKSpriteNode(imageNamed: "New_Background") backgroundNEW.size = self.size backgroundNEW.anchorPoint = CGPoint(x: 0.5 , y: 0) backgroundNEW.position = CGPoint(x: self.size.width , y: self.size.height * CGFloat(i)) backgroundNEW.zPosition = -1 backgroundNEW.name = "test" addChild(backgroundNEW) } } and var

How can I increase and display the score every second?

亡梦爱人 提交于 2019-12-13 07:50:51
问题 I am making a SpriteKit game in Swift. While gameState = inGame , I want the score to increase every second. How and where would I calculate and display something like this? The other answers I have found are outdated and not very helpful. There might be one I am not aware of that already exists, so I would be greatly appreciative if you could point me in that direction. Thanks for the help. 回答1: Here is a very simple way of incrementing and displaying a score every second, as you have

Detecting Touch on SKShapeNode that is a Line

天大地大妈咪最大 提交于 2019-12-13 07:39:12
问题 I have an SKShapeNode that I have created and given a CGPath to. This is in my GameScene.swift in didMoveToView: let myNode = SKShapeNode() let lineToDraw = CGPathCreateMutable() CGPathMoveToPoint(lineToDraw, nil, 0, 0) CGPathAddLineToPoint(lineToDraw, nil, 87, 120) myNode.path = lineToDraw myNode.strokeColor = SKColor.redColor() myNode.lineWidth = 20 myNode.name = "My Node!" world.addChild(myNode) // World is a higher-level node in my scene And this is how I'm detecting touches, again in the

Swift 3: cut a hole in a SKSpriteNode

我与影子孤独终老i 提交于 2019-12-13 07:32:27
问题 First of all: I know, that this questions has already many answers here, but they didn't helped me to solve this this problem. I program a little game. At the first launch there is a little tutorial, where bit by bit each element of the game is explained. In each step I want to highlight one of these elements. So I put a black SKSpriteNode with an alpha of 0.9 in front of the elements. If an element should be highlighted, the SpriteNode should become transparent at this point. So I made an

Swift SpriteKit basic Contact / Collision

放肆的年华 提交于 2019-12-13 07:15:12
问题 The problem: When the coin spawns, it's physicsBody appears right underneath the spriteNode. Also, when the player comes in contact with the coin's physicsBody, the player bounces off of the physicsBody and the game ends. What the output should be: The coin's physisBody should be aligned properly with the coin spriteNode. When the player comes in contact with the coin, the coin should disappear and +1 should be added to the proper label. The current code: struct ColliderType { static let

SKAction Perform Selector syntax error

ⅰ亾dé卋堺 提交于 2019-12-13 06:58:11
问题 Using a SKAction sequence I am trying to add a delay and then call a method with two parameters, however I keep getting the following (new to obj c so could be something simple): // code SKAction *fireAction = [SKAction sequence:@[[SKAction waitForDuration:1.5 withRange:0], [SKAction performSelector:@selector(addExplosion:firstBody.node.position andTheName: @"whiteExplosion") onTarget:self]]]; // error Expected ':' Method declaration -(void) addExplosion : (CGPoint) position andTheName :

Transition from SKScene to UIViewcontroller

。_饼干妹妹 提交于 2019-12-13 06:51:35
问题 For example if i have: class SpriteKitScene: SKScene { ... } And in there i want to have an image, that when tapped(pressed, clicked, touched whatever) loads another file with: class UiViewcontrollerScene: UIViewcontroller { ... } I know how to transition from SKScene to SKScene, but i need to transition from SKScene to UIViewcontroller. 回答1: First, set yourself up a delegate using a protocol for your view controller. protocol UIViewControllerDelegate{ } See here: https://makeapppie.com/2014

iAd freezes game's scene

流过昼夜 提交于 2019-12-13 06:46:42
问题 I am developing a game using SpriteKit. I have iAds displayed in a view on the scene. When an ad in the Ad view is touched, the Ad appears, however, if I cross(X)/close the ad the scene in the game is frozen. I do not pause the scene or do anything on the events when the Ad appears and disappears. If I touch the ad again (now this is second time with frozen scene) and return to the scene, the scene un-freezes and everything starts to work as they were suppose to (strangely). I am not sure

Sprite Kit: Is there a way to disable the scale mode and code what you want to happen

[亡魂溺海] 提交于 2019-12-13 06:46:11
问题 I'm building a universal app using Sprite Kit, Objective C. This app is aimed for OS X as well as iOS platforms. A problem that many people will have encountered is the positioning of objects on the screen as different devices have different proportions. I have read up many answers/posts online to solve this issue and have come to the conclusion that there seem to be only a few options available to the programmer when it comes to solving this which is selecting the appropriate scaling modes