skspritenode

How to add a SKSpriteNode to the scene in Swift?

我的未来我决定 提交于 2020-01-06 21:59:33
问题 I tried to subclass SKSpriteNode into GameObject and I would like to instantiate objects outside the game scene class. Here is my GameObject code derived from SKSpriteNode : import SpriteKit public class GameObject: SKSpriteNode { init( texture: SKTexture?, color: UIColor, size: CGSize, position:CGPoint, name:String ) { objectSize = size; objectName = name; objectSprite = texture; //call superclass here super.init(texture: texture, color: color, size: size); self.position = position; }

SKAction.moveToX repeat with value change

女生的网名这么多〃 提交于 2020-01-06 15:17:47
问题 i want to be able move the ball with pause every 20 pixels moved i tried this one but didn't do nothing, the ball stays at the point where it started it doesn't move to the end of the screen,i know i didn't put the waitForDuration , because i wanted to check if it will move or not func spwan() { let ball:SKSpriteNode = SKScene(fileNamed: "Ball")?.childNodeWithName("ball") as! SKSpriteNode ball.removeFromParent() self.addChild(ball) ball.name = "spriteToTrack" ball.zPosition = 0 ball.position

sort a SKSpriteNode array according to a specific element

流过昼夜 提交于 2020-01-05 21:17:20
问题 I have a SKSpriteNode array declared like this : class rgbNodes: SKSpriteNode { } var colorNode = [rgbNodes]() colorNode.append(rgbNodes(imageNamed: "Rectangle")) // every time we want to add a new element to this array And I would like to sort every element of this array according to their position.x value, for example, if : colorNode[0].position.x = 25 colorNode[1].position.x = 5 colorNode[2].position.x = 15 I want the array to be sorted like this : colorNode[0].position.x = 5 colorNode[1]

Spritekit: Efficiently create many SpriteNodes

不打扰是莪最后的温柔 提交于 2020-01-03 03:14:29
问题 I am using SpriteKit to write a bullet-hell style shoot-em-up, and the SK framework seems to be able to handle hundreds of nodes at 60fps without any problems at all. My problem however is that sometimes I need to spawn 50+ nodes in a single frame, and that does seem to cause the odd hitch in framerate. Are there any tricks I should be using to make sure that creation of many nodes is as performant as possible? I am re-using SKTextures, should I also have a persistent collection of

Confusion about coordinates, frames & child nodes in SpriteKit on iOS?

╄→尐↘猪︶ㄣ 提交于 2020-01-02 02:42:07
问题 I'm still playing around with learning SpriteKit in iOS & have been doing lots of reading & lots of experimenting. I'm confused by something else I've found* regarding coordinates, frames & child nodes. Consider this snippet of code, in which I'm trying to draw a green box around my spaceship sprite for debugging purposes: func addSpaceship() { let spaceship = SKSpriteNode.init(imageNamed: "rocketship.png") spaceship.name = "spaceship" // VERSION 1 spaceship.position = CGPointMake

How to progressively blur a SKSpriteNode's image using Sprite Kit?

谁说我不能喝 提交于 2020-01-01 09:28:11
问题 Can someone provide an example of how to progressively blur a SKSpriteNode's image using Apple's Sprite Kit? For instance, let's say the user touches a button on the screen which will then trigger the background to slowly (i.e. progressively) blur until it reaches a specific threshold. Ideally, I would like to reverse the process too (e.g. allow the user to unblur the image by touching the same button). 回答1: There are two possible paths to take on this, both use SKEffectNodes SKEffectNodes

ObjectIdentifier needed for Swift equality?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-31 04:00:13
问题 We have multiple instances of a custom Swift class, which inherits from SKSpriteNode, and were able to execute the following code (grossly simplified for this question) correctly: let instance1 = CustomClass() let instance2 = CustomClass() let instance3 = CustomClass() let instance4 = CustomClass() let array1 = [instance1, instance2] let array2 = [instance3, instance4] func check(testInstance: CustomClass) -> Bool { return array1.filter({ $0 == testInstance }).count > 0 } check(testInstance:

Update Function Does Not Keep Up With Moving Sprite

点点圈 提交于 2019-12-25 16:51:42
问题 I have two sprites which a flush against each other. I'm moving one of the sprites around using a SKAction and moving the other sprite using the update function. Every time the update function is called, it calculates the position the second sprite needs to be at so that it continues to be flush against the first sprite. However, it seems the update function can not move the second sprite fast enough, as a gap appears between the two sprites. I assume the SKAction repositioning of the first

How to create multiple sprites(nodes) with the same texture that will automatically generate a new when one node is removed?

老子叫甜甜 提交于 2019-12-25 09:13:50
问题 I'm trying to create a game where the user can swipe a node and once it's swiped a new node will be created at the bottom of the screen and push all other nodes up, kind of like a reverse Tetris. Here is a very basic image to give you an idea: I've be able to figure out how to swipe the node off screen but can't seem to figure out how to have all the other nodes move up a row and have a new node created at the bottom. I tried doing an "addChild" for the node I just swiped so it can appear

increase game speed and keep same distance between nodes

北城余情 提交于 2019-12-24 19:47:15
问题 I am working on a game where I have two functions . The first function is used to create a row of obstacles. The gameSpeed variable is used to decide how frequently a new row of obstacles is added. Example : if I set gameSpeed to 3 then a new obstacle row is added every 3 seconds. func addobstalce() { lastYieldTimeInterval += timeSinceLastUpdate if lastYieldTimeInterval > gameSpeed { lastYieldTimeInterval = 0 nextRow(cR: currentRow) } } and the second function is used to add movement to them.