sprite-kit

How to make player move to opposite side while is in a path?

你说的曾经没有我的故事 提交于 2019-12-05 02:48:38
问题 I want that when touches began the player (red circle) moves to the opposite side of the circular path. I already made that the player follows a path, but I havent find answer to my question on internet. override func didMoveToView(view: SKView) { player = SKSpriteNode(imageNamed: "circulo") player.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2 - 170) player.color = colorGris player.colorBlendFactor = 1 player.size = CGSize(width: 25, height: 25) self.addChild(player)

How to draw SKNode PhysicsBody for debugging?

六月ゝ 毕业季﹏ 提交于 2019-12-05 02:39:53
I create my SKPhysicsBody with rectangle from size, I set it to size of the node, but the collision detection does not work on good portion of the node. How do I draw the red frame around physics body? I tried using precise collision detection, but it doesn't help. I have checked some debug library but it draws only direct descendants of the scene, and my nodes are few levels deep. Author apparently doesn't know what recursion is. How do I draw red frame around physics body if my body is rectangle? This works as of iOS 7.1 and in all OSX versions supporting SpriteKit. In this example I'm using

Memory problems when switching between scenes SpriteKit

核能气质少年 提交于 2019-12-05 02:39:25
问题 Ok so awhile back in testing I had a random crash with no error, and I have no clue why. So i went into analyze things and I came up with the following data. As it would appear my memory usage is getting higher and higher and higher until it sorta plateus. Notice how at the beginning the slope of the general curvature is greater then later on. (as you might notice this is my first time going in and analyzing this sort of thing). Now what happens in the game is that basically their are two

Double dispatch for collision handling with SpriteKit

跟風遠走 提交于 2019-12-05 02:34:30
问题 I'm using SpriteKit's collision detection. It has a callback that looks like this: - (void)didBeginContact:(SKPhysicsContact *)contact The contact object has two physics bodies: SKPhysicsBody *bodyA; SKPhysicsBody *bodyB; My game will have lots of objects, and of course I can test the categoryBitMask to find out what collided with what. But given that I intend to have many kinds (not more than 32 of course) and might dynamically introduce new types, what's the most elegant way to do dynamic

SpriteKit - Making a sprite defy gravity (like a balloon)

泪湿孤枕 提交于 2019-12-05 02:20:41
问题 Does anyone have any idea how I can make my SKSpriteNode defy gravity? I thought of inverting the default gravity but realise I also need things to fall too! It seems like it should be easy but reading through the documentation I can’t see how I would do it! Thanks 回答1: Update: In iOS 8 / OS X Yosemite (10.10), physics fields provide an elegant solution to these sorts of problems. Here's a quick take on using them to add buoyancy (for a specific set of nodes) to your scene. Create an

How do you use SKTextureFilteringNearest with SKTextureAtlas

ぃ、小莉子 提交于 2019-12-05 02:01:06
I seem to be having a problem using SKTextureAtlas and nearest neighbor filtering for textures. When I used the nearest neighbor filtering without SKTextureAtlas it works fine, but everything is just changed to linear filtering when I use an SKTextureAtlas. Code and Result Without SKTextureAtlas: SKTexture* texture = [SKTexture textureWithImageNamed:@"grass"]; texture.filteringMode = SKTextureFilteringNearest; SKSpriteNode* node = [SKSpriteNode spriteNodeWithTexture:texture size:CGSizeMake(512,512)]; Should Produce Nearest Neighbor Filtering & Does Code and Result With SKTextureAtlas:

Detect collision between two objects in Swift

爷,独闯天下 提交于 2019-12-05 01:38:13
问题 Collision detection is pretty simple in Swift - yet on this particular project, body collision is not triggering the didBeginContact event as usual. Here is my checklist for two bodies colliding (using soldiers and bullets): Add SKPhysicsContactDelegate to the class. set the physicsWorld appropriately, usually: self.physicsWorld.contactDelegate = self Create categories for each group of nodes you will have. E.g. let bulletCategory = 0x1 << 0 Create SKNodes for each bullet and soldier. Give

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

旧城冷巷雨未停 提交于 2019-12-05 01:26:34
问题 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

Subclassing SKShapeNode with Swift

和自甴很熟 提交于 2019-12-05 01:25:28
I'm trying to subclass SKShapeNode with Swift. So far I've got something like this: import UIKit import SpriteKit class STGridNode: SKShapeNode { init() { super.init() self.name = "STGridNode" self.fillColor = UIColor(red: 0.11, green: 0.82, blue: 0.69, alpha: 1) } } In my code I want so do something along the lines of: let s = STGridNode(rectOfSize: CGSize(width: 100, height: 100)) So my question is - how do I implement rectOfSize in the initialiser for STGridNode ? I've tried: init(rectOfSize: CGPoint) { super.init(rectOfSize: rectOfSize); } But that gives an error: 'Could not find an

SKShapeNode(circleOfRadius) results in “unrecognized selector sent to class” in Playground for OSX

雨燕双飞 提交于 2019-12-05 01:24:30
The following playground results in a timeline error "unrecognized selector sent to class..." import SpriteKit let node = SKShapeNode(circleOfRadius: 10) Screenshot Seems to work ok when platform is iOS. Running 10.9.3 It's because you're running it on an OS X version that's older than the API you're trying to use. The code you're using requires OS X 10.10, or iOS 8 and up. The OS X 10.10 API Differences confirm that all of SKShapeNodes custom initializers have just been added in 10.10. Previously, all we could do with SKShapeNode, was initialize an instance, and then modify its path property.