Join Todd Perkins for an in-depth discussion in this video Use forces and impulses, part of iOS Game Development with Swift 2.0 and SpriteKit.
- In SpriteKit, you can apply Forces and Impulses…to use physics to move objects around…while your code is running.…So let's look at how that works.…I'm going to select this ball in my game scene,…and I'm going to give it a name.…I'm just going to call it ball.…And that way I can reference it with my code easily.…So I'll save the file and head over to GameScene.swift,…and create a variable that I can use to reference my ball.…
Inside didMoveToView.…I'll set the value of ball = self.childNodeWithName…and the name is ball.…So what we want to do is when touchesBegan,…we want to shoot the ball up into the air…by applying a force, or an impulse.…You'll see that my code's getting an error,…and that's because I need to…data type it to SKSpriteNode.…So I'll do that right now.…There we go, and let's go down to touchesBegan,…and look at applying a force.…
So ball.physicsBody….applyForce,…and there's applyImpulse.…We can also apply it at a certain point, if we want.…Now the difference between a force and an impulse,…is that a force is meant to be applied over time.…
- 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.