We set up the SKLabelNode the same way we did earlier. The first function, setup(size:), is there just to set everything up. The last variable is a boolean that tells us whether we are currently presenting the high score (we use this to establish whether we need to run an SKAction to increase the scale of the scoreboard and to colorize it to the yellow of the floor). Next is our variable to hold the current score then the variable that holds the best score. The first variable is the actual SKLabelNode, which we use to present the label. In the code, we have five variables that pertain to the scoreboard. / Updates the score label to show the current score.īefore we do anything else, open up Constants.swift and add the following line to the bottom of the file - we will be using it to retrieve and persist the high score: let ScoreKey = "RAINCAT_HIGHSCORE" / - Resets color and size to default values. / - If a high score is achieved, then enlarge the scoreNode and update the color. ScoreNode.position = CGPoint(x: size.width / 2, y: size.height - 100) HighScore = defaults.integer(forKey: scoreKey) Private let scoreNode = SKLabelNode(fontNamed: "PixelDigivolve") Private let scoreKey = "RAINCAT_HIGHSCORE" This is the same process we followed when creating the background node in lesson one.Ĭreate the HudNode.swift file using the usual methods, and enter the following code: import SpriteKit The HUD will be an SKNode, acting like a container for our HUD elements. Delete the “Hello World” label, because we only used it to make sure our font loads. Now that we can load in custom fonts, we can start on our HUD. Code With Chris has a more in-depth troubleshooting guide, but note that it is for an older version of Swift, so you will have to make minor tweaks to bring it up to Swift 3. If it works, then you’ve done everything correctly. Label.position = CGPoint(x: size.width / 2, y: size.height / 2)ĭoes it work? Testing our SKLabelNode. Move to GameScene.swift, and in sceneDidLoad add the following code at the top of the function: let label = SKLabelNode(fontNamed: "PixelDigivolve") The font should be ready to use! We should do a quick test to make sure it works as intended. The plist should look like the following: Font added to plist successfully! Then, under Item 0, we need to add our font’s name. When the new row comes up, enter in the following: Fonts provided by application Right-click on the list, and click “Add Row.” Add a row to the plist. Click it and you will see the property list (or plist). If you miss this part, you probably won’t be able to use the font. Add a group named Fonts to the project, and add the Pixel digivolve.otf file. We’ve done this a few times in the previous lessons, so we’ll go through this process a little more quickly. This process can be tricky the first time.ĭownload and move the font into the project folder, under a “Fonts” folder. Next, we need to add the custom font to the project. You can’t always make everything yourself, so giving back to those who have helped you along the way is nice. This one states that it is free for personal use, but if you really like the font, you can donate to the author from the page. As with using images or sounds that are not yours, read the font’s license before using it. The font we will be using is Pixel Digivolve, which you can get at. For now, we will just focus on the score. This will be pretty simple it will be an SKNode that contains the score and a button to quit the game. To do this, we can create a heads-up display (HUD). Drag the images into Assets.xcassets again, just as we did in the previous lessons. The assets for the final lesson are available on GitHub. In the previous lesson, we had a long day going though some simple animations, cat behaviors, quick sound effects and background music. This is lesson three in our RainCat journey. Combining UX Design And Psychology To Change User Behavior.Playful UX Design: Building A Better Game.Gamification And UX: Where Users Win Or Lose.Remember that this tutorial requires Xcode 8 and Swift 3. If you missed out on the previous lesson, you can catch up by getting the code on GitHub. In part three of this three-part series, we will finish up our RainCat game and complete our introduction to SpriteKit. Have you ever wondered what it takes to create a SpriteKit game? Do buttons seem like a bigger task than they should be? Ever wonder how to persist settings in a game? Game-making has never been easier on iOS since the introduction of SpriteKit.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |