skspritenode

SKSpriteNode subclassing swift

让人想犯罪 __ 提交于 2019-12-06 04:13:28
问题 I have found a few posts on this but I'm still confused on how to do this. I know I have to use the "designated initializer" which is the init(texture: SKTexture!, color: UIColor!, size: CGSize). Really I won't use that anyway. I'd like to just add some properties to the sprite nodes. class Piece: SKSpriteNode { enum Type: Int { case type1 = 1, type2, type3, type4, type5 } var piecetype : Type init(texture: SKTexture!, color: UIColor!, size: CGSize) { self.piecetype = .type1 super.init

SKTexture get image name

天涯浪子 提交于 2019-12-06 03:47:05
Is there possible to get current image name from SKTexture from SKSpriteNode? I am a new in SpriteKit and I'm writing a little game. I need to detect when ninja will hit enemy. Something like this I am doing SKAction like - (void)setUpHit { SKTextureAtlas *hitAtlas = [SKTextureAtlas atlasNamed:@"Ninja_hit"]; SKTexture *hit1 = [hitAtlas textureNamed:@"Ninja_hit_1"]; SKTexture *hit2 = [hitAtlas textureNamed:@"Ninja_hit_2"]; SKTexture *hit3 = [hitAtlas textureNamed:@"Ninja_hit_3"]; SKTexture *hit4 = [hitAtlas textureNamed:@"Ninja_hit_4"]; SKAction *hitAnimation = [SKAction animateWithTextures:@

Stop SKSpriteNode from slowing down

…衆ロ難τιáo~ 提交于 2019-12-06 03:38:42
I am trying to keep my SKSpriteNodes moving at a constant speed forever, even after collisions. I have set gravity to 0, friction to 0, and linear and angular dampening to zero, but the Sprites still slowly slow down to zero velocity. How can I keep them moving? Based on the answer below, this is what I have tried: EDIT This code below works! I just had to check if the nodes were going slower than the limit and speed them up. [self enumerateChildNodesWithName:kBallName usingBlock:^(SKNode *node, BOOL *stop) { SKSpriteNode *ball = (SKSpriteNode *)node; if (ball.physicsBody.velocity.dx < 0) { if

SKPhysicsBody with restitution 0 still bounces

一个人想着一个人 提交于 2019-12-05 22:43:10
I'm am trying to drop the SKSpriteNode with constant speed and without bouncing. Here is the code I'm using: SKSpriteNode *floor = [SKSpriteNode spriteNodeWithColor:[UIColor clearColor] size:CGSizeMake(self.size.width, 1)]; floor.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:floor.size]; floor.physicsBody.restitution = 0.0f; floor.physicsBody.dynamic = NO; floor.physicsBody.allowsRotation = NO; SKSpriteNode* block = [SKSpriteNode spriteNodeWithTexture:[SKTexture textureWithImageNamed:imageName]]; block.position = CGPointMake(160, 300); block.physicsBody = [SKPhysicsBody

SpriteKit - Nodes adjusting position a tiny bit

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 21:25:07
I have a number of individual nodes (tiles) that make up the background of my game. They're each 32x32p, and are positioned next to each other to form floor/ roof/ obstacles. I load a map from a JSON-file, and position the nodes on a background-layer/node based on the contents of the JSON-file when the scene is initialized. This is working fine, however, I'm experiencing some bugs when moving the background layer/ the physics engine is doing its thing. Some of the nodes move 1 point/pixel away from each other, creating a gap between them. And since the background is a different color, this

Make edges of SKSpriteNode look smooth after rotation

本秂侑毒 提交于 2019-12-05 21:22:40
I create a SKSpriteNode like that: var shape:SKSpriteNode = SKSpriteNode(color: UIColor.redColor(), size: CGSizeMake(CGFloat(sizeOfShape), CGFloat(sizeOfShape))) How can I achieve, that a SKSpriteNode has still smooth edges, after I've rotated it. Currently, it looks like that: As you see, the edges are jagged. 来源: https://stackoverflow.com/questions/25532760/make-edges-of-skspritenode-look-smooth-after-rotation

SKSpriteNode : Handling Collision during SKAction

别说谁变了你拦得住时间么 提交于 2019-12-05 18:40:52
I'm making a little game, and I'm now stuck with the following problem. I'm running an action (followPath type) on a particular node : let followTrack: SKAction = SKAction.followPath(ballPath!.CGPath, duration: ACTION_SPEED) movingBall.runAction(followTrack) But during the animation, if the node collide with another one (like a wall for exemple), the animation stops and there is no collision animation. I tried some things like : func didBeginContact(contact: SKPhysicsContact) { var firstBody: SKPhysicsBody = contact.bodyA var secondBody: SKPhysicsBody = contact.bodyB firstBody.node?

SKTexture nearest filtering mode doesn't work (Making Pixel Art)

懵懂的女人 提交于 2019-12-05 16:49:33
I used a relatively small image (44pixel tall) and scaled it up to have a pixel art look. I tried to change the filtering mode to nearest so the anti-aliasing would disappear but it didn't. It appears with blurry edges. I tried the same with a background getting the same result. let myNode = SKSpriteNode() class GameScene: SKScene { func makeNode() { myNode.position = CGPoint(x: self.frame.size.width/2, y: self.frame.size.height/2) myNode.size = CGSize(width: 200, height: 200) myNode.texture = SKTexture(imageNamed: "image") myNode.texture!.filteringMode = .Nearest return self.addChild(myNode)

Centre a SKLabelNode on a SKSpriteNode

落爺英雄遲暮 提交于 2019-12-05 15:21:02
问题 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)? 回答1: 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

Swift SKSpriteNode: Detect Tap / DoubleTap / LongPress

旧巷老猫 提交于 2019-12-05 10:05:40
I'm attempting to create a subclass of SKSpriteNode which can detect user interaction (tap, double tap and hold), then defer to a delegate. This seems to me like a relatively common need, but: The code is incapable of detecting a double-tap without also triggering a single-tap. I haven't found a way to detect hold/long-press actions at all. Am I going about this all wrong? I can't help feeling that SpriteKit should have something standard to handle something so basic. I know there's UIGestureRecognizer, but it doesn't seem very compatible with specific SKNodes rather than UIViews. Here's what