Sometimes you want to stop an action while it's running. This tutorial shows how to save a reference to an action so you can stop it later.
- [Instructor] So let's say you have an action…that's running forever and you want…to stop it at a certain point.…If you want to stop an action, you need to give it a key.…So what I'm going to do is change…this run method on line 49…to run action with key.…to run action with key.…So I'll pass in that repeat action…and then I'm going to pass in the key.…I'll call this item move.…Now you may want to, if you're using these keys…and you have a whole bunch of them,…set them as constants in your code…instead of using a literal string.…
But for what we're doing a string literal is fine.…So let's scroll down.…And let's say we want to stop the item moving…when we click our mouse down on the screen.…So I'm going to scroll down and I'm going to find touchdown.…And at the bottom of this method,…I'm going to call item,…I'm going to call item.removeAction(forKey…and note that there's also removeAllActions.…So if you want to stop all the actions…running down the object you can do that…without having to save the key.…But for a specific action, you need the key.…
- Creating a SpriteKit project
- Adding and modifying sprites
- Creating sprites in code
- Transitioning between scenes
- Working with children and parents
- Adding physics
- Detecting and responding to collisions
- Applying particle effects
- Creating actions
- Working with sound
- Adding cameras and lights
Skill Level Intermediate
Careers in the Game Industrywith Christian Bradley1h 19m Beginner
Building a Game App with the Android SDKwith David Gassner2h 6m Intermediate
1. Introduction to SpriteKit
2. Add Physics
3. Work with Particle Effects
4. Work with Actions
5. Work with Audio
6. Additional Features
Next steps1m 41s
- 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.