sprite-kit

iOS9 Sprite Kit issues

我的未来我决定 提交于 2019-12-06 17:12:30
问题 Everything was going so well until I upgraded to xCode 7 and iOS 9.... My current project is a 2D platform game, ever since the upgrade I've fallen fowl of the sprite kit bug/errors that many of us seem to be facing. My issue is that all sprites appear randomly in terms of their zPosition position each time the game runs on either simulator or device. I've been scouring stack for an answer without luck, so far I've tried. Moving all images to .xcassets Like described here Changing the iOS

SpriteKit SKTextureAtlas, Terminated Due to Memory Pressure while loading texture

大兔子大兔子 提交于 2019-12-06 16:41:26
Similar to the SpriteKit Featured Game "Adventure" from WWDC, I am try to load my background image via tiles. I have created a Texture Atlas that contains 6,300 "tiles" that are each 100x100 pixels in size. The complete background image is a total of 30,000x2048 (for retina displays). The idea is that the background will move from right to left (side-scroller). The first column and the last column match so that they seem continuous. When the application runs, it loads my initial loading screen and title images and spikes to 54MB in my memory tab with a CPU usage of 16% . This stays the same as

CGPointMake in Swift

假装没事ソ 提交于 2019-12-06 16:36:44
问题 How to use CGPointMake in Swift ? Is there an equivalent for it? I am getting an error: Use of unresolved identifier 'CGPointMake' Basically, I am trying to assign a position to a Sprite Kit node and cannot figure out how to do it in Swift. class PlayerSpaceship: Spaceship { func launchMissile() { var missile = Missile.playerMissile() // This line gives above mentioned error. missile.position = CGPointMake(0.0, 0.0) } } 回答1: Use CGPoint(x: Float, y: Float) 回答2: You call it a little

Using an .sks file to layout a complex object vs a SKScene file

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 16:29:37
Is it possible to use the SceneEditor to layout & create a complex Subclass of SKSpriteNode, load that information and create a custom object in your scene based on the sks file? My scenario is that I have a popup dialogs (which are nothing more than subclasses of SKSpriteNodes) with a lot of children on the dialog. I was hoping to lay it out in the Scene editor similar to how I lay out an SKScene, and then present it in my scene when needed. I realize that I could just create this object in my GameScene.sks file, but find that those can get easily cluttered, and thought it might be a nicer

iOS Sprite Kit how to reflect a sprite horizontally? [duplicate]

痴心易碎 提交于 2019-12-06 16:02:06
This question already has answers here : Horizontally mirror a SKSpriteNode texture (4 answers) Closed 5 years ago . Is there a way to create a SKSpriteNode and pass it an image name, but have it reflect the image horizontally? You mean you want to flip the image? node.xScale = node.xScale * -1; or node.yScale = node.yScale * -1; 来源: https://stackoverflow.com/questions/21008886/ios-sprite-kit-how-to-reflect-a-sprite-horizontally

How to pause and restart NSTimer.scheduledTimerWithTimeInterval in spritekit [SWIFT] when home button is pressed?

三世轮回 提交于 2019-12-06 16:02:02
问题 I'm new to swift & spritekit and wanted to know how is it possible to detect if the home button is pressed ? The main problem is that I have NSTimer.scheduledTimerWithTimeInterval running to generate multiple characters in didMoveToView , and everything is going well, but when I pause the game with home button and restart the game a few seconds later, the characters floods out alot. I assume that the NSTimer had not been paused , therefore, flooding alot of characters when relaunching the app

Sharing highscore with social media

浪尽此生 提交于 2019-12-06 15:38:15
问题 I Want that when the player is done with the level, he can click a button(shareButton) so an UIActivityviewcontroller pops up where the player can share its highscore with the social media. But my problem is, the button is in the GameScene, but the UIActivityviewcontroller can only be called in the GameViewController.. how do I do this? Game starts with GameMenuScene, when play is clicked it will move to GameScene: class GameMenuScene: SKScene { if nodeAtPoint.name == "play"{ NSUserDefaults

SpriteKit PhysicsBody: Could not create physics body

此生再无相见时 提交于 2019-12-06 15:36:37
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 textureWithImageNamed:@"player_flying"]; self.player.physicsBody = [SKPhysicsBody bodyWithTexture:self.player.texture size

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

Shoot bullet in the Direction the Ship is Facing Swift and Sprite Kit

喜你入骨 提交于 2019-12-06 15:07:36
问题 I am making a space shooter game, and I would like the ship to be able to fire bullets in the direction it is facing. I have figured out how to make the bullet rotate in the direction of the ship, but I haven't gotten it to shoot in the right direction. At the moment, I only shoot up. I have a screen shot down below. How can I fix this? Here is my code: if shootButton.containsPoint(location) { let Bullet = SKSpriteNode(imageNamed: "BulletGalaga.png") Bullet.zPosition = -5 Bullet.position =