sprite-kit

How to store user data in game? (swift, spritekit)

落花浮王杯 提交于 2019-12-11 05:18:31
问题 Let's say I had a game where in the beginning the user gets to choose a couple of things like name, gender, etc, and that will affect a lot of aspects in the game such as the sprite used to render the user, and the text that is displayed. So every time I leave one area of the game and enter a new one I should figure out according to the user data - what sprite to use and what text to prep. Should I make a separate class with a dictionary just for the user's data and then just call it whenever

SpriteKit ball speed differ on size

爷,独闯天下 提交于 2019-12-11 05:15:26
问题 I am creating a ball by SKShapeNode and CGPathAddArc . The thing is if I use a larger radius the ball moves slower. If I use a lower radius the ball moves faster. // width depends on screen size (iphone, ipad) // on iPhone the speed of the ball is something I like // when on the ipad the speed is very slow CGPathAddArc(ballPath, NULL, 0, 0, self.frame.size.width/80, 0, M_PI*2, YES); How do I make it(movement speed) constant whatever the radius is? _ball.physicsBody = [SKPhysicsBody

Set touchable area of SKSpriteNode

最后都变了- 提交于 2019-12-11 04:57:52
问题 Is there a property of SKSpriteNode that lets you manually set its touchable area? I have a sprite textured with a PNG, it only seems to detect touches on the opaque portion of the PNG. So a small circle inside a large blank canvas actually has a tiny touchable area. 回答1: Create an SKNode that is the size you would like the touchable area to be. Add your textured sprite as a child of the new SKNode. Check to see if the new SKNode was touched instead of if the textured sprite was touched. 回答2:

How to present ads during certain scenes in sprite-kit?

主宰稳场 提交于 2019-12-11 04:55:34
问题 This is my first time developing an app using swift and sprite-kit. I would like to integrate adMob into it. I have been searching a solution to my problem but I've had no success. I have the following code set up inside GameViewController.swift override func viewDidLoad() { super.viewDidLoad() bannerView = GADBannerView(adSize: kGADAdSizeSmartBannerPortrait) bannerView.isHidden = true bannerView.adUnitID = "ca-app-pub-************************" bannerView.rootViewController = self view

Why SKNode isn't reacting to touch in SpriteKit game?

风流意气都作罢 提交于 2019-12-11 04:48:39
问题 In order to make a pause in a SpriteKit game I made a pause button. It worker like a charm when I wanted to make an another scene for pause and respond to touch was transitioning to a scene. My function then looked like this (P.S. pause = pause button) But there were other problems with it and I decided to make pause within my main scene: playscene So I added a pauseBackground and resumeButton that is attached to pause background and hided it (declared resumeButton.hidden = true ) Now my

How to animate multiple SKSpriteNode together?

ⅰ亾dé卋堺 提交于 2019-12-11 04:25:57
问题 I am pretty new to SpriteKit . I have a set of nodes that need to move together to a different point for each node and after that animation completed for all of them I would like to do something else. I was making this with UIView components before. A [UIView animateWithDuration:completion:] block was providing the thing that I needed. But in SpriteKit each node has its own action and animate by itself. I could not find any block animation for sprite nodes. So I cannot control the animation

Generate an image of the contents of a SKScene which is not displayed

三世轮回 提交于 2019-12-11 04:25:28
问题 In my current SKScene, I use UIGraphicsGetImageFromCurrentImageContext to generate an image from the current graphics on screen. However, I would like to generate an image from a scene not on screen. One I have created but have not displayed. Is this possible? The reason for doing is this is to create a custom image for users to share when they achieve a high score, which is similar, but not the same as my main Scene. 回答1: Here is a method that captures the contents of a node as a PNG. Be

SpriteKit Sprites Not Scaling Properly

眉间皱痕 提交于 2019-12-11 04:25:27
问题 The sprites in my SpriteKit game, though properly scaled, are being rendered extremely small in my scenes. I've been following a few different tutorials using similarly sized sprites and theirs are scaled fine in the simulator. Below are some code snippets and screenshots. For example, the pause button on the top right of the screen is crazy small, yet the actual resolutions of the assets are standard in size. GameScene.swift private let pauseTex = SKTexture(imageNamed: "PauseButton") ...

Programmatically creating an SKTileDefinition

一个人想着一个人 提交于 2019-12-11 04:24:50
问题 I've been beating my head against a wall for hours now. I am trying to modify a texture inside my app using a CIFilter and then use that new texture as a part of a new SKTileDefinition to recolor tiles on my map. The function bellow finds tiles that players "own" and attempts to recolor them by changing the SKTileDefinition to the coloredDefinition . func updateMapTileColoration(for players: Array<Player>){ for player in players { for row in 0..<mainBoardMap!.numberOfRows { for col in 0..

Pausing scene when game was interrupted

雨燕双飞 提交于 2019-12-11 04:24:26
问题 Another question: I call the function which generates sprites per time. But when I interrupt the game, for example picking up the call or double-click home button and go to task-manager, my scene doesn't stop and continue calling this function (oh, in this function i recall it per random time, cause in didMoveToView it calls once). So how stop the scene when game was interrupted? Thank you! func spawnRocks(){ if gameOver == 0{ score++ scoreLabel.text = "\(score)" let rockPosition = arc4random