sprite-kit

Coordinate System in SpriteKit

痞子三分冷 提交于 2019-12-06 05:06:51
I am quite confused with the spritekit coordinate system. I need clarification on two cases. Case 1: When a sprite node is added as child to the scene: SKSpriteNode * blueBall = [SKSpriteNode spriteNodeWithImageNamed:@"hRedBall.png"]; blueBall.name=@"blueball"; blueBall.size=CGSizeMake(75, 75); blueBall.position=point; //I am varying this point [self addChild:blueBall]; I have added the node at different points each time.These are the points I added the node at: (100x100)(200x200)(300x300)(400x400)(900,600) And in my iphone 5 device, they look like this: If you look into 100x100, when I add

Keeping an object within the screen. Swift SpriteKit

给你一囗甜甜゛ 提交于 2019-12-06 05:04:36
问题 I am new to swift a Sprite kit. In the app I am trying to make I have a submarine moving through the ocean. Every time the user clicks the screen the gravity starts pulling the sub in the opposite direction. My problem is that i can't find a way to keep the sub from leaving the screen. I have tried to solve it by making a physicsBody around the screen, but the sub still leaves the screen. I have also tried the following code in the updateCurrentTime fund. override func update(currentTime:

Sprite Kit touchesbegan: delay/lag

拥有回忆 提交于 2019-12-06 04:27:46
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touch"); ... } I have a really simple problem that I can't find any answers to. Most of the time, when I tap the screen, the nslog executes immediately. However, about 1 in 5 times, there is a half second pause before the message displays. I'm making a game and I need the touchesbegan to execute immediately. Can anyone tell me what I'm doing wrong? BTW, the framerate is a mostly constant 60 fps. 来源: https://stackoverflow.com/questions/23047732/sprite-kit-touchesbegan-delay-lag

Calculating delta in SpriteKit using Swift

空扰寡人 提交于 2019-12-06 04:27:29
I am attempting to learn swift by refactoring one of my old games and I need to rewrite my update method which calculates a delta time. This code works but is ugly. How would I go about properly rewriting this? import SpriteKit class GameScene: SKScene { var lastUpdateTimeInterval: CFTimeInterval? override func update(currentTime: CFTimeInterval) { var delta: CFTimeInterval? if let luti = lastUpdateTimeInterval { delta = currentTime - luti } else { delta = currentTime } lastUpdateTimeInterval = currentTime; if (delta > 1.0) { delta = minTimeInterval; lastUpdateTimeInterval = currentTime; }

Choosing random image for SKSpriteNode

点点圈 提交于 2019-12-06 04:26:32
I am trying to build a simple obstacle jumping app. I want the image for the obstacle to be picked randomly from a set of images. I have tried using a combination of the arc4random_uniform function and switch case but that doesn't seem to update the SKSpriteNode. What am i doing wrong? class PlayScene: SKScene, SKPhysicsContactDelegate{ ... var block3 = SKSpriteNode(imageNamed: "lion") .... } override func update(currentTime: NSTimeInterval) { ..... blockRunner() } func blockRunner() { var imageNamedAnimal = "" var randomIndex = arc4random_uniform(2) switch(randomIndex) { case 0 :

Is there a way to invert the colors of a SKSpriteNode

萝らか妹 提交于 2019-12-06 04:21:42
问题 I was wondering if it was possible to invert the colors (or adjust the hue) of a SKSpriteNode. 回答1: You can invert the colors by applying a CIFilter with an SKEffect node. Something like this should work: SKEffectNode *effectNode = [[SKEffectNode alloc] init]; effectNode.filter = [CIFilter filterWithName:@"CIColorInvert"]; SKSpriteNode *node = yourNode; // Make sure this node doesn't already have a parent [effectNode addChild:node]; [self addChild:effectNode]; Note that an SKScene is an

What is causing my SKAction timer to behave strangely?

纵然是瞬间 提交于 2019-12-06 04:19:16
Okay, I have a scene in which I have this method, createSceneContents , that gets called when didMoveToView gets called. In this method I have a couple of things that create the scenes, including a timer that spawns nodes like this: self.spawningSpeed = 1.5; self.enemyData = [[Enemy alloc]init]; SKAction *wait = [SKAction waitForDuration:1.5]; SKAction *run = [SKAction performSelector:@selector(spawningEnemy) onTarget:self]; self.spawnAction = [SKAction repeatActionForever:[SKAction sequence:@[wait,run]]]; [self.world runAction:self.spawnAction withKey:@"spawn"]; enemyData is an object of my

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:@

Swift: SKAction.runBlock -> Missing argument for parameter 'completion' in call BUT WHY?

六月ゝ 毕业季﹏ 提交于 2019-12-06 03:41:38
问题 I'm noobie in Swift. I can't figure out why this code: class GameScene: SKScene, SKPhysicsContactDelegate { var statements = Statements() override func didMoveToView(view: SKView) { runAction(SKAction.repeatActionForever( SKAction.sequence([ SKAction.runBlock(addLabel(statements)), SKAction.waitForDuration(2.0) ]) )) } func addLabel(statements: Statements) {...} } Results to: Missing argument for parameter 'completion' in call 回答1: Yet another weird bug in the type checker. Because the type