Join Todd Perkins for an in-depth discussion in this video Remove a child from its parent, part of iOS Game Development with Swift 2.0 and SpriteKit.
- View Offline
- Exercise Files
- Just as a child can be added to a parent…and appear on the screen,…if a child is removed from it's parent…it will be removed from the screen.…Let's look at how that works in code.…So I'm working in GameScene.swift…and this is just the default SpriteKit template…code right here,…and inside did move to view a label is created,…so instead of a constant that's created there,…let's just make it an instant property…so we can remove it later on.…
So we'll go up a few lines above override didMoveToView…and I'll define the variable myLabel to be…of the type SKLabelNode and I'll add an exclamation point…to make it an implicitly unwrapped optional…and then I'll just delete let on line 16.…So now I can reference this later on.…And inside of touches began I'm going to just delete…all of the existing code.…Now just as we add the child to it's parent…to bring it on the screen,…we need to tell the child to be removed from it's parent…to take it off of the screen.…
So I'm going to call myLabel.removeFromParent…You'll notice the other methods are removeChildrenInArray,…
- Creating a new SpriteKit project
- Adding and modifying sprites
- Transitioning between scenes
- Removing child sprites from parents
- Working with gravity, forces, and impulses
- Detecting collisions
- Applying particle effects
- Creating actions and action sequences
- Working with audio
- Creating frame animations
- Using cameras and lights
Skill Level Intermediate
Programming iOS 9 and GamePlayKitwith Tammy Coron1h 32m Intermediate
1. Introduction to SpriteKit
2. Add Physics
3. Work with Particle Effects
4. Work with Actions
Use an action sequence4m 8s
5. Work with Audio
6. Additional Features
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.