skspritenode

How to set bounds to Scene physics body to bounce properly?

那年仲夏 提交于 2019-12-13 18:51:28
问题 I implemented a simple physics to bounce a sprite node , and everything worked except the node is bouncing off the screen for the top and bottom.It is fine for the sides, but it goes off the screen for top and bottom view. Here is the view: As you can see, I the ball is going off the screen at the bottom, where it perefectly touches the other three sides. This is because, I made a change to: self.physicsBody=[SKPhysicsBody bodyWithEdgeLoopFromRect:CGRectMake(self.frame.origin.x, self.frame

Basic Swift SpriteKit Collisions using PhysicsBodys

社会主义新天地 提交于 2019-12-13 17:42:50
问题 The problem: I seem to be having a little trouble getting my player to collide with a coin, and adding +1 to a coinLabel upon the collision. The player should continue moving after coming in contact with the coin. What I have now: With the code I have now, the player travels through the coin, but there is no collision that takes place and +1 isn't added to the coin label. I am still learning the swift language, so I appreciate any help that is given. Code: struct ColliderType { static let

Using custom SKNodes in spritekit scene editor

▼魔方 西西 提交于 2019-12-13 12:06:39
问题 I want to create a level using my custom subclasses of SKNode. I tried adding an SKNode to the scene editor and using the "Custom Class" tab give the class that I want it to be but that did absolutely nothing. The node would still be empty and nothing would show when I run the simulator. Also, to make sure that the class actually works, I added an instance of it to the scene programmatically to see if it shows and it does. How do I add my custom nodes to the scene through the scene editor?

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

SKSpriteNode does not have member named ''- how to access a variable declared in my spawn method?

喜夏-厌秋 提交于 2019-12-13 04:52:06
问题 I asked another question before about how to access a global variable in Swift, but realized the global variable did not work for my purposes. Some background: The game is a math/match game. Player's will have an equation, and they have to get the sheep with the matching answer. I have sheep that spawn on screen. Each sheep holds a unique int value (1-12) that is generated within my spawnSheep method: var sheepValue: Int = Int(arc4random_uniform(UInt32(12))+1) Multiple sheep will spawn on

Unexpectedly Found Nil SKSpriteNode

旧巷老猫 提交于 2019-12-13 02:22:12
问题 I get the following error when there's contact between bullet and the plane. fatal error: unexpectedly found nil while unwrapping an Optional value Plane Function: func addPlane() { var myplane : SKSpriteNode? myplane = SKSpriteNode(imageNamed: "plane") let actualY = random(min: 100, max: size.height - myplane!.size.height/2) myplane!.position = CGPoint(x: size.width + myplane!.size.width/2, y: actualY) myplane!.physicsBody = SKPhysicsBody(rectangleOfSize: myplane!.size) // 1 myplane!

Multiple Contacts Issue in SpriteKit Game

依然范特西╮ 提交于 2019-12-13 00:15:10
问题 In my game, I have a ball, walls and gaps between these walls. Ball and walls are SKSpriteNode, gap is SKNode. I use gap to count the score. I have the following code to handle the contacts and collisions. I checked plenty of documents and tutorials but cant find why there are multiple gap contacts happen when my ball contacts the gap. It prints "gap contact" for 6 times every time. Bodytypes definitions: enum BodyType:UInt32 { case ball = 1 case wall = 2 case gap = 4 } Ball: var ball =

Random value in Swift

偶尔善良 提交于 2019-12-12 17:30:19
问题 I'm trying to have a value who is between 0 and the size of my screen. So i did it like this : let sizeX = Int(CGRectGetMaxX(self.frame)) let sizeY = Int(CGRectGetMaxY(self.frame)) var randomX = CGFloat(arc4random()) % sizeX var randomY = CGFloat(arc4random()) % sizeY self.touchButton.position = CGPointMake(randomX, randomY) I have this error : could not find an overload for '%' that accepts the supplied arguments I need this to randomize the position of an SkSpriteNode, maybe is there a

SkSpriteNode.Run Action don't Works some times

北战南征 提交于 2019-12-12 10:21:42
问题 this is my first SpriteKit game and I didn't had any problems with run action before so I tried but can't figure anything out, only thing I figure out is all code is fine but just run action don't execute some times and didn't seen any king of behaviour in that pattern. I I'm making 4 player board game and all 4 players have 4 pieces. the problem is with returning to home when ever any player piece kills other player's piece that piece comes back to home before it was working fine but I added

SKTexture nearest filtering mode doesn't work (Making Pixel Art)

心不动则不痛 提交于 2019-12-12 09:39:44
问题 I used a relatively small image (44pixel tall) and scaled it up to have a pixel art look. I tried to change the filtering mode to nearest so the anti-aliasing would disappear but it didn't. It appears with blurry edges. I tried the same with a background getting the same result. let myNode = SKSpriteNode() class GameScene: SKScene { func makeNode() { myNode.position = CGPoint(x: self.frame.size.width/2, y: self.frame.size.height/2) myNode.size = CGSize(width: 200, height: 200) myNode.texture