skspritenode

Handling Multiple GestureRecognizers

点点圈 提交于 2019-12-04 04:10:12
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(testTap(recognizer:))) main.addGestureRecognizer(mainScene.tapRecognizer) mainScene.pinchRecognizer =

Centre a SKLabelNode on a SKSpriteNode

寵の児 提交于 2019-12-04 02:55:10
I have an SKLabelNode that is the child of a SKSpriteNode because I'm trying to create a Button class to create buttons in an easier way. I've tried a couple of things using the anchor point of the SKSpriteNode, but I don't quite understand exactly what is going on. How do I centre the label onto the sprite (it's parent node)? I realized how to solve this...here's what i did. Keep in mind that I have a class called Button that is a subclass of SKSpriteNode. In the Button.m class I have an instance variable called label that is a SKLabelNode. I add the label node as a child to the button then

iOS - bodyWithPolygonFromPath : Body is the same as the path but collisions are not working properly

我的未来我决定 提交于 2019-12-03 16:36:14
First i'd like to say thanks to every users on this website because i'm always finding solutions here and it's sooo helpful ! I'm trying to make a game like Xonix, Bix or Jezzball with SpriteKit. Anyway, i have a ball bouncing against walls, and i'm trying to make obstacles where it can't go, those obstacles are made from CGPathref (the user makes it with its movements) I'm using bodyWithPolygonFromPath to create the physicsbody of the skspritenode, it's working, but not always. I've downloaded YMCPhysicsDebugger to see the content of the body, and in every case, it's good, but i've seen that

Blend UIColors in Swift

我怕爱的太早我们不能终老 提交于 2019-12-03 14:54:23
I have two SKSpriteNode and their colors are defined like this: colorNode[0].color = UIColor(red: 255, green: 0, blue: 0, alpha: 1) colorNode[1].color = UIColor(red: 0, green: 255, blue: 0, alpha: 1) and I want to have a third SKSpriteNode colorized with a blend of the two first ones, the result should be like this : colorNode[2].color = UIColor(red: 255, green: 255, blue: 0, alpha: 1) but is there a way to addition two UIColors ? Like this : colorNode[2].color = colorNode[0].color + colorNode[1].color How about something like this: func addColor(_ color1: UIColor, with color2: UIColor) ->

How to copy SKSpriteNode with SKPhysicsBody?

走远了吗. 提交于 2019-12-03 14:17:01
I am curious about a situation that I came across today when trying to unarchive and copy a SKSpriteNode from one SKScene to another. In the output from the playground below you can see that both linearDamping and angularDamping or not being maintained after the copy (they seem to be dropping back to default values) // PLAYGROUND_SW1.2 - SKSpriteNode Copy import UIKit import SpriteKit // ORIGINAL let spriteNode = SKSpriteNode() spriteNode.name = "HAPPY_NODE" let size = CGSize(width: 55.0, height: 150.0) let physics = SKPhysicsBody(rectangleOfSize: size) physics.linearDamping = 0.123 physics

In swift how do I change the color of a SKSpriteNode?

社会主义新天地 提交于 2019-12-03 12:04:17
问题 I have created a game with an SKSpriteNode that is black and when the user touches the screen I would like for the SKSpriteNode to change to white. I have googled everything I can and attempted lots of different strategies with no luck. Does anyone know how to do this? Here's the code for my scene: var blackBird = SKSpriteNode() override func didMoveToView(view: SKView) { //Black Bird var blackBirdTexture = SKTexture(imageNamed:"blackbird") blackBirdTexture.filteringMode =

Make SKSpriteNode subclass using Swift

不想你离开。 提交于 2019-12-03 09:44:47
I'm trying to create class which is a subclass of SKSpriteNode and I want to add other properties and functions to it. But in the first step I faced an error. Here's my code: import SpriteKit class Ball: SKSpriteNode { init() { super.init(imageNamed: "ball") } } It's not a compile error, It's run-time error. It says: Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) and fatal error: use of unimplemented initializer 'init(texture:)' for class Project.Ball . How can I fix it? Mike S You have to call the designated initializer for SKSpriteNode . I'm actually surprised you didn't

In swift how do I change the color of a SKSpriteNode?

怎甘沉沦 提交于 2019-12-03 02:34:55
I have created a game with an SKSpriteNode that is black and when the user touches the screen I would like for the SKSpriteNode to change to white. I have googled everything I can and attempted lots of different strategies with no luck. Does anyone know how to do this? Here's the code for my scene: var blackBird = SKSpriteNode() override func didMoveToView(view: SKView) { //Black Bird var blackBirdTexture = SKTexture(imageNamed:"blackbird") blackBirdTexture.filteringMode = SKTextureFilteringMode.Nearest blackBird = SKSpriteNode(texture: blackBirdTexture) blackBird.setScale(0.5) blackBird

SKSpriteNode frame way off

让人想犯罪 __ 提交于 2019-12-02 11:04:40
问题 I am trying to create an open circle from a UIBezierPath and turn that into an SKShapeNode which will later be turned into a SKSpriteNode. I had an problem where I could not figure out how to shrink a Sprite while its line width did not scale down. You can see the solution here: Resize sprite without shrinking contents I ended up fixing some things and creating a new class to implement a custom SKShapeNode with this functionality: class ShrinkableShape: SKShapeNode { let level: Int let

SpriteKit - How to fix distortion in Node's animation?

一曲冷凌霜 提交于 2019-12-02 09:43:37
I have created an animation of various PNGs, but there are various frames that stretch to the border so the node is 'filled'. The animation should look like the GIF that I have created using the same pictures. Does anybody know how to make the animation look like the GIF? GIF: Gif: Animation should look like this Actual: Extra slow Actual result of the code Border: Here you can see the border of the physics body that has the same size of the "node's border" I have tried to fix the problem by switching the scene.scalemode. Further, I have tried to make the size of the Node dependent on the size