sprite-kit

SpriteKit PhysicsBody: Could not create physics body

独自空忆成欢 提交于 2019-12-08 07:57:00
问题 I have a player in my game, it has two states flying, falling. Each of them has an image: player_flying, player_falling correspondingly. I am also using a physical bodies to detect collision. It is completely normally functioning when I use one texture. But when I am trying to use both in different conditions using different textures, it shows me an error in the log. I am trying it like that: if (self.player.physicsBody.velocity.dy > 30) { self.player.texture = [SKTexture

Force change interface orientation between scenes

旧巷老猫 提交于 2019-12-08 07:46:43
问题 How can I force the game to switch from portrait (Scene 1) to landscape mode (HomeScene) in between scenes? I have two scenes, Scene1 (which is portrait) and HomeScene (which is designed to be landscape) I am calling this line from Scene 1. -(void)gotoHome { //Would like to change interface orientation here. HomeScene *scene = [HomeScene sceneWithSize:self.size]; [self.view presentScene:scene]; } Problem is, both the scenes are being rendered on the same view. How can I tell a viewController

How do you change the color of all of the nodes of a specific name in SpriteKit with Swift

有些话、适合烂在心里 提交于 2019-12-08 07:34:14
问题 I'm trying to change the color of every single instance of a node in SpriteKit. When I try to put it in the update method, it only changes one and not all of them. override func update(currentTime: CFTimeInterval) { if changeColor { self.enumerateChildNodesWithName("blocks", usingBlock: { node, stop in block?.color = UIColor.orangeColor() }) } } 回答1: I think you should change the color of the node , not of some block variable. You will retrieve all SKNode s with that name. But those nodes don

dealing with different screen sizes in xcode

我的未来我决定 提交于 2019-12-08 07:24:21
问题 I have an iPhone game that was first developed for iPhone 6 and when played on the iPhone 5 sim it works fine but when played on the iPhone 4 sim the sides are stretched out?!? and the nodes that I spawn in from the left and the right side spawn on the screen instead of off the screen like on the iPhone 6 and 5. (please don't say this is a duplicate as I have been looking for weeks of how to deal with different iPhones) I have arrows coming in the from the left and the right that spawn

iOS: drawbacks of disabling Metal API Validation in order to fix pipeline failed assertion?

隐身守侯 提交于 2019-12-08 07:20:46
问题 Adding a SKEmitterNode to a SceneKit Scene via a SpriteKit overlay generates the following exception: -[MTLDebugRenderCommandEncoder validateFramebufferWithRenderPipelineState:]:1196: failed assertion `For color attachment 0, the render pipeline's pixelFormat (MTLPixelFormatRGBA8Unorm_sRGB) does not match the framebuffer's pixelFormat (MTLPixelFormatBGR10_XR).' This exception occurs on an iPhone 7 device, but does not appear in the simulator. Searching online yielded one valid workaround:

SKEmitterNode iOS 9 GM problems

一个人想着一个人 提交于 2019-12-08 06:45:18
问题 This is the code I used in iOS 8 to get the particle to appear: func onCollision() { let explosion = SKEmitterNode(fileNamed: "rocketExplosion") explosion.position = rocket.position explosion.zPosition = 100 addChild(explosion) } Worked fine for iOS 8 but not for iOS 9. I've read that there were problems with the particle emitters in the beta, are they still the same in GM version? Also, I tried this after a "Swift 2" tutorial but no luck: if let explosion = SKEmitterNode(fileNamed:

how to count number of sprites swift

陌路散爱 提交于 2019-12-08 06:39:44
问题 I'm building an app that add sprites to the screen. In several parts of my code I want to know how many sprites I have with a certain key. At the moment I implemented it in this way var counter = 0 enumerateChildNodesWithName("box") { node, _ in counter = counter + 1 } println(counter) Is there another easier and shorter way? Thanks 回答1: From iOS8 , SKNode has subscript member that queries nodes and returns Array<SKNode> . extension SKNode { subscript (name: String) -> [SKNode] { get } } So

SpriteKit help understanding scaling

倖福魔咒の 提交于 2019-12-08 06:35:20
问题 Making a portrait only game using SpriteKit and putting my image assets into Images.xcassets . This is for iPhone, so my image assets are setup like so: 1x, 2x, Retina 4 2x, 3x For example, under one image asset, a 2x, I have a 640x640 png, this fits fine on iPhone 4/4s, 5/5s but on 6 (which also scales @ 2x) it doesn't, because the 6 has a slightly wider screen @ 750px (or 375 points). So I came-up with the following formula which I can pass into [mySprite setScale:] for each and every

How to force SKTextureAtlas created from a dictionary to not modify textures size?

 ̄綄美尐妖づ 提交于 2019-12-08 06:32:33
问题 In my project, textures are procedurally generated from method provided by PaintCode (paint-code). I then create a SKTextureAtlas from a dictionary filed with UIImage generated by these methods : myAtlas = SKTextureAtlas(dictionary: myTextures) At last, textures are retrieve from atlas using textureNamed : var sprite1 = SKSpriteNode(texture:myAtlas.textureNamed("texture1")) But displayed nodes are double sized on iPhone4S simulator. And triple sized on iPhone 6 Plus simulator. It seems that

Randomizing SKActions

我与影子孤独终老i 提交于 2019-12-08 06:32:06
问题 I'm trying to move a Sprite over the screen from left to right. The sprite should start at a random y position on the right side offscreen. With a repeatActionForever and an integer with a random Y number i want the sprite to repeat the action starting from different y Positions. Any ideas on how to achieve this besides putting the random int in an update method? Is it anyhow achieveable through actions? I use this method on the Sprite: int randomY = (arc4random()%121; SKAction *pos =