sprite-kit

SKlabelNode custom font

江枫思渺然 提交于 2019-12-06 10:15:47
I know I can create a custom font using this code: [UIFont fontWithName:@"bebas-neue" size:10]; But if I want to create an SKLabelNode, how can I set this as the font? SKLabelNode only takes a string as the fontName. The procedure is essentially the same as for UIFont . To do this from scratch, follow the same process as for adding a custom UIFont (described here ), then just use: [SKLabelNode labelNodeWithFontNamed:@"Font Name Here"] 来源: https://stackoverflow.com/questions/21368283/sklabelnode-custom-font

Pausing game during call, Difference between getting a call and pressing home button?

旧巷老猫 提交于 2019-12-06 10:01:59
My game pauses ok when home button is pressed. But it doesn't when I get a call. Its actions are resumed when the game becomes active. I don't get the difference between getting a call and pressing HB. Please help me out. Thanks. func pauseGame(){ initResumeButton() pause.removeFromParent() gamePaused = true self.paused = true } func resumeGame(){ resume.removeFromParent() initPauseButton() gamePaused = false self.paused = false } func registerAppTransitionObservers(){ NSNotificationCenter.defaultCenter().addObserver(self, selector: "applicationWillResignActive", name:

.png animation slow performance in spritekit

混江龙づ霸主 提交于 2019-12-06 10:01:25
i have a .png animation in my project with 700 pics and a size of 150 px x 150 px. it works fine but everytime, the animation starts, the whole game freezes for about 0.1 sec. like its loading but i implemented the .png array in initWithSize. like this: SKTextureAtlas *barrierUfoAtlas = [SKTextureAtlas atlasNamed:@"BarrierUfoAnimation"]; NSArray *barrierUfoAtlasNames = [barrierUfoAtlas textureNames]; NSArray *sortetBarrierUfoAtlasNames = [barrierUfoAtlasNames sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; NSMutableArray *barrierUfoTextures = [NSMutableArray array]; for

SKLabelNode text with two different fonts and colour. How is this possible?

本小妞迷上赌 提交于 2019-12-06 09:40:30
I have an SKLabelNode which is set up to show the Score Variable followed by the Highscore variable scoreLabel.text = "\(score)/\(classicHScoreInt)" Now, everything shows fine but i would like the classicHScoreInt to be a smaller font and maybe a different colour. How is this possible? classicHScoreInt is (as stated) an integer and so is score You cannot set two fonts to the same SKLabelNode instance. Instead you can write subclasses to create a custom node which contains multiple SKLabelNodes with different font sizes. For example, Your scoreLabel can be an instance of the following class.

SpriteKit: Passing variable from GameViewController to GameScene

孤街浪徒 提交于 2019-12-06 09:36:14
I created a menu in Storyboard that passes some information through a segue to GameViewController. Ideally, I could use that segue to pass the information directly to GameScene.swift where I need it, but I'm not sure that's an option since a scene is just a view and not a view controller. So, I pass the information to the GameViewController and that works great. But now, how to I get it to GameScene.swift? Segue from menu to GameViewController func passToGame(game: String) { performSegue(withIdentifier: "toGameSegue", sender: game) } override func prepare(for segue: UIStoryboardSegue, sender:

Restarting Sprite - Kit Game Swift

我是研究僧i 提交于 2019-12-06 09:01:09
I have created a simple 2D arcade game using SpriteKit and I am trying to add a scoring system.Basically the game is a square sprite which has to jump over various obstacles. So what I want is when the player contacts the object for the whole game to restart. The game detects the contact (I tested it previously) but when I remove all my children and then run my game's basic main function I notice that old objects keep spawning and cluttering with each other. func didBegin(_ contact: SKPhysicsContact) { if (contact.bodyA.categoryBitMask == PhysicsCategory.Player && contact.bodyB.categoryBitMask

How check the .spriteatlas sizes generated by Xcode?

孤人 提交于 2019-12-06 08:47:05
I'm using texture atlas for handling my images. I didn't created the atlas by myself however I let Xcode to do this for me: My question is: How can I see this file or know its properties (I mean, sizes and weight)? What if and how can I know if the sizes exceed the maximum size of 4098 x 4098 pixel? 来源: https://stackoverflow.com/questions/33561727/how-check-the-spriteatlas-sizes-generated-by-xcode

Swift SpriteKit - Gradually increase rotation

核能气质少年 提交于 2019-12-06 08:25:40
I'm experimenting round with @nickfalk's answer on How to rotate sprite in sprite kit with swift on how to rotate a sprite in sprite kit. How would I adjust this to gradually increase rotation speed up to a maximum, then when the screen is clicked, it gradually slows down and goes in the reverse direction for x amount of time? Thanks! Toby. T. Benjamin Larsen Ok, the following (slightly messy proof of concept) spins a sprite at a constant speed. Upon tap+hold it gradually slows the rotation to a halt. Ending the touch immediately returns the rotation to full speed. I've set up a scene with the

Resizing a SKShapeNode

我怕爱的太早我们不能终老 提交于 2019-12-06 08:25:31
问题 How do I resize a SKShapeNode? What I've tried so far: Frame resize box.frame.width = 10 Gives the error Cannot assign to the result of this expression SKAction let actionResize = SKAction.resizeToWidth(10, duration: NSTimeInterval(0.1)) box.runAction(actionResize) Nothing happens xScale box.xScale = 0.1 Scales the node instead of resizing 回答1: The action, resizeToWidth , can be called by an SKSpriteNode. You can call the action, scaleTo , with SKShapeNode. 回答2: Change it to a var: var

iCarousel in Sprite Kit

泄露秘密 提交于 2019-12-06 08:17:24
Explanation I'm trying to build a character selection menu similar to Crossy Road's one (as you can see here ). So I found this iCarousel , which would help me with all of it, but everything I read talk about implementing it to a ViewController , which isn't my case. I'm using GameScene and I didn't found anything talking about it. Is there anyway I could implement it to my game? or even another effect similar to the character selection menu I mentioned above? Attempt (beyowulf) You can download it here . GameScene.swift import SpriteKit class GameScene: SKScene { var show = SKSpriteNode() var