skspritenode

Confusion about coordinates, frames & child nodes in SpriteKit on iOS?

依然范特西╮ 提交于 2019-12-05 04:22:30
I'm still playing around with learning SpriteKit in iOS & have been doing lots of reading & lots of experimenting. I'm confused by something else I've found* regarding coordinates, frames & child nodes. Consider this snippet of code, in which I'm trying to draw a green box around my spaceship sprite for debugging purposes: func addSpaceship() { let spaceship = SKSpriteNode.init(imageNamed: "rocketship.png") spaceship.name = "spaceship" // VERSION 1 spaceship.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)) let debugFrame = SKShapeNode(rect: spaceship.frame)

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

How to copy SKSpriteNode with SKPhysicsBody?

我怕爱的太早我们不能终老 提交于 2019-12-04 23:41:31
问题 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,

how Xcode automatically remove skspritenode form its parent's node

落花浮王杯 提交于 2019-12-04 17:38:27
I'm new in objectif-c and sprite-kit development (but not in programming). So I'm starting the Apple's Spri. The app works perfectly, except that the nodes representing the rocks are automatically removed form its parent when rocks fall through the bottom of the scene. This, without implementing the -(void)didSimulatedPhysics method : - (void)didSimulatedPhysics { [self enumerateChildNodesWithName:@"rock" usingBlock:^(SKNode *node, BOOL *stop) { if (node.position.y < 0) [node removeFromParent]; }]; } I can see that with the nodes counter shown on the screen : it doesn't increase with the

Make SKSpriteNode subclass using Swift

吃可爱长大的小学妹 提交于 2019-12-04 15:39:06
问题 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? 回答1

Is there a way to make a soft body with Spritekit using SKSpriteNode and PhysicsBody parameters?

这一生的挚爱 提交于 2019-12-04 14:46:15
I have the following sprite that falls to the bottom of the screen: // The View self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame]; self.physicsWorld.contactDelegate = self; // The Sprite SKSpriteNode *cube = [[SKSpriteNode alloc] initWithImageNamed:@"cube"]; [cube setPosition:CGPointMake(160,250); [self addChild:cube]; // The Physics cube.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:cube.frame.size]; cube.physicsBody.dynamic = YES; cube.physicsBody.affectedByGravity = YES; cube.physicsBody.mass = 0.02; Is there a way to make it so its sides are bulging when it hits

SpriteKit SKTexture Crash

℡╲_俬逩灬. 提交于 2019-12-04 06:36:13
问题 Not sure why this doesnt work. It crashes with EXC_BAD_ACCESS when it tries to create the ship node. SKTexture *tex = [SKTexture textureWithImageNamed:@"Spaceship"]; CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone"]; [filter setValue:@0.6 forKey:kCIInputIntensityKey]; SKTexture *texDone; if (filter) { texDone = [tex textureByApplyingCIFilter:filter]; } if (texDone) { SKSpriteNode *ship = [SKSpriteNode spriteNodeWithTexture:texDone]; [self addChild:ship]; ship.position = CGPointMake

Changing the image of a SKSprite to an SKShapeNode

梦想的初衷 提交于 2019-12-04 05:33:57
问题 Sprite Kit, Xcode. I need to find a way to change a sprites image within the program itself. I know how to create jpg files and make them into the sprite image... But for this program, I need to draw circles/polygons (which may change inside the program) using SKShapeNode, and then transferring this to the SKSpriteNode's image. Let's say I have declared: SKSpriteNode *sprite; SKShapeNode *image; How would I do this with these variables? Thanks! EDIT: I mean texture when I say image. 回答1: If I

How to add a swipe gesture to a node in spritekit

回眸只為那壹抹淺笑 提交于 2019-12-04 05:01:57
问题 I'm trying to add a swipe gesture to a node so that when a user swipes it, it goes off screen but I keep getting a SIGABRT error: `Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[fidget2.PlankScene swipedRight:]: unrecognized selector sent to instance 0x7ff4c3603e00'` I'm not sure why this error is popping up. I made sure the node is labeled correctly in the .sks file. Here is my code: import SpriteKit let plankName = "woodPlank" class PlankScene: SKScene {

How to progressively blur a SKSpriteNode's image using Sprite Kit?

柔情痞子 提交于 2019-12-04 04:59:05
Can someone provide an example of how to progressively blur a SKSpriteNode's image using Apple's Sprite Kit? For instance, let's say the user touches a button on the screen which will then trigger the background to slowly (i.e. progressively) blur until it reaches a specific threshold. Ideally, I would like to reverse the process too (e.g. allow the user to unblur the image by touching the same button). There are two possible paths to take on this, both use SKEffectNodes SKEffectNodes allow you to apply CI Filters to a node. There is a CI Filter for Gaussian Blur. So Create a SKEffectNode, and