sknode

SpriteKit: how to smoothly animate SKCameraNode while tracking node but only after node moves Y pixels?

廉价感情. 提交于 2019-12-24 00:48:51
问题 This question and others discuss how to track a node in SpriteKit using a SKCameraNode. However, our needs vary. Other solutions, such as updating the camera's position in update(_ currentTime: CFTimeInterval) of the SKScene, do not work because we only want to adjust the camera position after the node has moved Y pixels down the screen. In other words, if the node moves 10 pixels up, the camera should remain still. If the node moves left or right, the camera should remain still. We tried

swift - Jump only when landed

江枫思渺然 提交于 2019-12-23 15:37:53
问题 I'm looking to restrict my character (cat), to only jump when it's either on the ground (dummy SKNode), or when on the tree (treeP SKNode). Currently I don't have any restrictions to touchesBegan and as a result the cat is able to fly through the air if the user clicks in quick succession, whilst this could be useful in other games it's not welcome here. If anyone could help me I'd be really happy. What i would like to do but have no experience would be to enable a click (jump), if the cat

SKAction: how to generate a random delay in generation of nodes

夙愿已清 提交于 2019-12-23 04:02:31
问题 I use the following piece of code to generate SKNodes periodically. Is there a way to make the period of generation of these SKNodes random. Specifically, how do I make the "delayFish" in the following code an action with a random delay? [self removeActionForKey:@"fishSpawn"]; SKAction* spawnFish = [SKAction performSelector:@selector(spawnLittleFishes) onTarget:self]; SKAction* delayFish = [SKAction waitForDuration:3.0/_moving.speed]; SKAction* spawnThenDelayFish = [SKAction sequence:@

Sprite Kit bodyAtPoint and bodyInRect return incorrect values?

时光总嘲笑我的痴心妄想 提交于 2019-12-21 04:57:04
问题 I created a very simple sample code, just one scene, one sprite node 20x20px, at point 0.0 on screen. When I call scene.physicsWorld bodyAtPoint it returns me this node even at point eg: 34x34. But at point 35x35 it returns null . So basically all points from 0px to 34px in both axis returns this node, starting from 35px, it doesn't return it anymore. Any idea what could be the reason, if sprite visibly ends at 20px 20px? The same behaviour is seen in bodyInRect . Here is the sample code: -

Cannot cast SKNode to subclass of SKNode

大兔子大兔子 提交于 2019-12-11 12:35:42
问题 I am returning an SKNode from one function and I need to cast it to a custom SKNode . I get the error Cannot assign value of SKNode to type GroundNode. If I force cast, it compiles, but fails at runtime. What am I missing? // Custom node class class GroundNode: SKNode { weak var entity: GKEntity! } // Return node function func returnNode() -> SKNode { ... return node } // Where I am getting the error func setupNode() { var ground: GroundNode ground = returnNode() // error here. //// ground =

SpriteKit childNodeWithName can't find existing node

前提是你 提交于 2019-12-11 05:58:42
问题 I have this code in SKScene: override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) { var touch: AnyObject = touches.anyObject() var point = getPoint(touch.locationInNode(self)) var name = NSStringFromCGPoint(point) for children in self.children { if (children as SKSpriteNode).name == name { println("exist!") } } var tempNode = self.childNodeWithName(name) } I see "exist!" in log, so there is a node with this name in children array, but tempNode is nil . The self

Swift-Making an SKNode simply “move forward” on an angle

半城伤御伤魂 提交于 2019-12-08 08:16:49
问题 I've already asked this question in a different way here; Swift-Setting a physics body velocity by angle but the three attempts to answer it were unfortunately not exactly what I'm looking for, although I'm grateful for what they taught me anyway. I decided that I should simply rephrase my question with an example and further explanation instead of perpetuating a discussion via comments. So here it is. Imagine I have an SKNode positioned in the centre of the screen. Let's say this is a ball,

How can you detect if SKShapeNode is touched?

旧城冷巷雨未停 提交于 2019-12-08 06:13:07
问题 I created a sknodeshape. How can I detect if the shape I made was touched(clicked)? Here is the code: (I solved it already) //metung_babi is the name of the SKShapeNode UITouch *touch = [touches anyObject]; CGPoint nokarin = [touch locationInNode:self]; SKNode *node = [self nodeAtPoint:nokarin]; if ([node.name isEqualToString:@"metung_babi"]) { NSlog(@"touch me not"); } my mistake was when I created the shape I put the SKShapeNode name before initializing it. 回答1: Implement the touch delegate

Swift-Setting a physics body velocity by angle

吃可爱长大的小学妹 提交于 2019-12-08 05:06:33
问题 I was wondering if it was at all possible to make an SKNode move forward in a particular direction, but with only one factor. I'm aware of both applying an impulse and setting the velocity of a physics body, but they're both determined by two factors; dx and dy. I also know of rotating to an angle with SKActions. But is it possible to make an object simply "move forward" once it has been set on an angle? Or set its velocity with just one factor? Thanks in advance. 回答1: Sure I think what you

Why does [NSSet containsObject] fail for SKNode members in iOS8?

空扰寡人 提交于 2019-12-07 16:57:18
问题 Two objects are added to an NSSet , but when I check membership, I can't find one of them. The test code below worked fine in iOS7 but fails in iOS8. SKNode *changingNode = [SKNode node]; SKNode *unchangingNode = [SKNode node]; NSSet *nodes = [NSSet setWithObjects:unchangingNode, changingNode, nil]; changingNode.position = CGPointMake(1.0f, 1.0f); if ([nodes containsObject:changingNode]) { printf("found node\n"); } else { printf("could not find node\n"); } Output: could not find node What