sknode

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

落花浮王杯 提交于 2019-12-07 15:06:26
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, so any rotation action on it is not visible. I would need a way to have a random angle selected, and

Loading an SKNode from a .sks scene file in Swift

天涯浪子 提交于 2019-12-07 05:19:22
问题 I want to use multiple .sks files to store some complex SKNode hierarchies such as game menus. I have a background with moving objects I'd like to keep throughout the game, so presenting different SKScenes doesn't achieve what I want. I am restricted to one scene, but I'd still like to separate out my code from artwork as much as possible, and trying to squeeze everything into one .sks file gets crowded quick! So I'd like to have multiple .sks files, each one storing a different menu:

Jumping to a specific SKNode in node hierarchy

♀尐吖头ヾ 提交于 2019-12-07 03:22:34
问题 I have noticed that the SKNode methods children and childNodeWithName: as the name implies only return results from the children directly below the queried node. i.e. [root children]; will return an NSArray containing the nodes @[CUBE1, CUBE2, CUBE3] . In the diagram below I want to get from the ROOT (SKScene) level down to SPHERE2 so that I can quickly access that nodes children. I was hoping that [root childNodeWithName:@"SPHERE2"]; would traverse the whole hierarchy and return a pointer to

Swift-Setting a physics body velocity by angle

本小妞迷上赌 提交于 2019-12-07 03:13:20
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. Sure I think what you're talking about is something like this: Now let's say you have an SKSpriteNode that is called player who

Strange Exception with GameCenter

若如初见. 提交于 2019-12-07 01:34:13
问题 I keep getting this crash report from GA and users... However i cannot reproduce this exception by testing iphone5,5s,6 with both ios7 and ios8. This issue comes nowhere when application did enter to background. The strange part is that gamecenter will call spritekit, for showing achievement banner? Does anyone has the same issue? Last Exception Backtrace: 0 CoreFoundation 0x23c99e3f __exceptionPreprocess + 127 1 libobjc.A.dylib 0x31371c8b objc_exception_throw + 38 2 CoreFoundation 0x23c9f189

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

荒凉一梦 提交于 2019-12-06 15:20:09
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:@[spawnFish, delayFish]]; SKAction* spawnThenDelayFishForever = [SKAction repeatActionForever

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

老子叫甜甜 提交于 2019-12-05 19:52:23
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 happened between iOS7 and iOS8, and how can I fix it? Karl Voskuil SKNode 's implementations of isEqual

How to render a SKNode to UIImage

懵懂的女人 提交于 2019-12-05 16:44:35
问题 Just playing around with SpriteKit and am trying to figure out how to capture a 'grab' of an SKNode into a UIImage. With UIView (or a UIView subclass), I have used the layer property of the view to render into a graphics context. Eg. #import <QuartzCore/QuartzCore.h> + (UIImage *)imageOfView:(UIView *)view { UIGraphicsBeginImageContextWithOptions(view.frame.size, YES, 0.0f); CGContextRef context = UIGraphicsGetCurrentContext(); [view.layer renderInContext:context]; UIImage *viewShot =

Jumping to a specific SKNode in node hierarchy

不问归期 提交于 2019-12-05 08:10:05
I have noticed that the SKNode methods children and childNodeWithName: as the name implies only return results from the children directly below the queried node. i.e. [root children]; will return an NSArray containing the nodes @[CUBE1, CUBE2, CUBE3] . In the diagram below I want to get from the ROOT (SKScene) level down to SPHERE2 so that I can quickly access that nodes children. I was hoping that [root childNodeWithName:@"SPHERE2"]; would traverse the whole hierarchy and return a pointer to SPHERE2 MY QUESTION: Is there something that I have missed that will let me jump into a node tree at a

ObjectIdentifier needed for Swift equality?

放肆的年华 提交于 2019-12-02 03:12:52
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: instance3) In other words, executing check(testInstance: instance3) returned false as expected. However