Recording
How to make a jumping platformer game on xcode 7! - part 1
2015-12-06 · 11 min
Machine transcript · wording, timing and speaker attribution may be wrong
Wording, speaker labels, and timestamps can still be wrong. A transcript does not establish that statements in the recording are factual. Use the source links and surrounding context.
Source information & transcript revisions
Transcript revisions
- rev_57470d71da7371197d4792ae608db03cMachine-generated and unreviewed; may be wrong; not a verified quotation.enraw_asractive196 segments
Transcript
Hey guys, welcome to this Xcode video.
Segment details
0:00–0:03 · rev_57470d71da7371197d4792ae608db03c_0Today I'm going to teach you how to make a
Segment details
0:04–0:07 · rev_57470d71da7371197d4792ae608db03c_1character jump up and down. For example,
Segment details
0:07–0:10 · rev_57470d71da7371197d4792ae608db03c_2if you want to make like a platforming
Segment details
0:10–0:12 · rev_57470d71da7371197d4792ae608db03c_3game, this could be useful. So the
Segment details
0:12–0:16 · rev_57470d71da7371197d4792ae608db03c_4first thing we're going to do is New
Segment details
0:17–0:18 · rev_57470d71da7371197d4792ae608db03c_5Project, Single View Application,
Segment details
0:18–0:20 · rev_57470d71da7371197d4792ae608db03c_6and you can just call your product
Segment details
0:22–0:24 · rev_57470d71da7371197d4792ae608db03c_7whatever. You want to,
Segment details
0:25–0:28 · rev_57470d71da7371197d4792ae608db03c_8and Objective-C, iPhone, and then Next.
Segment details
0:29–0:32 · rev_57470d71da7371197d4792ae608db03c_9Okay, then just do Create.
Segment details
0:33–0:35 · rev_57470d71da7371197d4792ae608db03c_10Okay, first thing you want to do is— it's
Segment details
0:37–0:39 · rev_57470d71da7371197d4792ae608db03c_11up to you, but I like to put it into
Segment details
0:40–0:42 · rev_57470d71da7371197d4792ae608db03c_12landscape, so turn off Portrait. You can
Segment details
0:42–0:45 · rev_57470d71da7371197d4792ae608db03c_13do this in portrait as well if you want,
Segment details
0:45–0:46 · rev_57470d71da7371197d4792ae608db03c_14but I think it looks better in landscape.
Segment details
0:46–0:48 · rev_57470d71da7371197d4792ae608db03c_15And then we go to Main Storyboard.
Segment details
0:49–0:51 · rev_57470d71da7371197d4792ae608db03c_16And just close this left tab. Now what
Segment details
0:52–0:56 · rev_57470d71da7371197d4792ae608db03c_17it's done is it's in auto layout.
Segment details
0:56–1:01 · rev_57470d71da7371197d4792ae608db03c_18I like to turn auto layout off and disable
Segment details
1:01–1:04 · rev_57470d71da7371197d4792ae608db03c_19size classes, so this gives you the iPhone
Segment details
1:04–1:06 · rev_57470d71da7371197d4792ae608db03c_20size, not that strange square shape. And
Segment details
1:07–1:10 · rev_57470d71da7371197d4792ae608db03c_21then we go to the 4th tab along— no,
Segment details
1:11–1:14 · rev_57470d71da7371197d4792ae608db03c_223rd— no, wait, click on the top first and
Segment details
1:14–1:17 · rev_57470d71da7371197d4792ae608db03c_23then do 4th tab along, Orientation, and
Segment details
1:17–1:20 · rev_57470d71da7371197d4792ae608db03c_24then Landscape or Portrait depending what
Segment details
1:20–1:22 · rev_57470d71da7371197d4792ae608db03c_25you want. Okay, so now
Segment details
1:23–1:26 · rev_57470d71da7371197d4792ae608db03c_26we need to create the floor and our
Segment details
1:27–1:29 · rev_57470d71da7371197d4792ae608db03c_27character and the jump button. So we need
Segment details
1:30–1:32 · rev_57470d71da7371197d4792ae608db03c_28an ImageView. We need 2 of these
Segment details
1:32–1:34 · rev_57470d71da7371197d4792ae608db03c_29ImageViews, and make sure these arrows are
Segment details
1:34–1:37 · rev_57470d71da7371197d4792ae608db03c_30in the center and click off— turn off
Segment details
1:38–1:41 · rev_57470d71da7371197d4792ae608db03c_31these outer ones. And then just
Segment details
1:41–1:46 · rev_57470d71da7371197d4792ae608db03c_32reshape it how you want the floor to look
Segment details
1:46–1:48 · rev_57470d71da7371197d4792ae608db03c_33like. It can be like really big or really
Segment details
1:48–1:50 · rev_57470d71da7371197d4792ae608db03c_34small. And then just copy, Command+C,
Segment details
1:51–1:54 · rev_57470d71da7371197d4792ae608db03c_35Command+V, and then just resize it for
Segment details
1:54–1:57 · rev_57470d71da7371197d4792ae608db03c_36your character. Now he can be skinny, or
Segment details
1:58–2:01 · rev_57470d71da7371197d4792ae608db03c_37he can be fat, or he could be short. It's
Segment details
2:01–2:03 · rev_57470d71da7371197d4792ae608db03c_38up to you. Just place him on the floor.
Segment details
2:04–2:05 · rev_57470d71da7371197d4792ae608db03c_39Now select all of them. Command A,
Segment details
2:07–2:10 · rev_57470d71da7371197d4792ae608db03c_40and then go into the fourth tab and go on
Segment details
2:11–2:13 · rev_57470d71da7371197d4792ae608db03c_41Image. Now we didn't need an image. I have
Segment details
2:13–2:16 · rev_57470d71da7371197d4792ae608db03c_42this red red square prepared. Just drag
Segment details
2:16–2:19 · rev_57470d71da7371197d4792ae608db03c_43it, drag it onto and do Finish, and then
Segment details
2:19–2:23 · rev_57470d71da7371197d4792ae608db03c_44it will appear here red dot PNG.
Segment details
2:24–2:26 · rev_57470d71da7371197d4792ae608db03c_45Now on on Image, just type in the file
Segment details
2:27–2:30 · rev_57470d71da7371197d4792ae608db03c_46name. Hold on.
Segment details
2:30–2:33 · rev_57470d71da7371197d4792ae608db03c_47It's not appearing, so just type it as it
Segment details
2:35–2:39 · rev_57470d71da7371197d4792ae608db03c_48appears here, red.png, and it will show
Segment details
2:39–2:43 · rev_57470d71da7371197d4792ae608db03c_49you the image as the one you typed in.
Segment details
2:43–2:45 · rev_57470d71da7371197d4792ae608db03c_50Okay, so we also need a button, so search
Segment details
2:46–2:49 · rev_57470d71da7371197d4792ae608db03c_51for a button at the bottom right, drag it
Segment details
2:49–2:51 · rev_57470d71da7371197d4792ae608db03c_52on, and you can just name it jump or
Segment details
2:52–2:55 · rev_57470d71da7371197d4792ae608db03c_53something. And I don't know why as default
Segment details
2:55–2:59 · rev_57470d71da7371197d4792ae608db03c_54it always starts off like this. But if you
Segment details
2:59–3:01 · rev_57470d71da7371197d4792ae608db03c_55don't change it, if you don't change it to
Segment details
3:02–3:04 · rev_57470d71da7371197d4792ae608db03c_56the center arrows, then it's going to be
Segment details
3:04–3:06 · rev_57470d71da7371197d4792ae608db03c_57in a different location when you play the
Segment details
3:07–3:08 · rev_57470d71da7371197d4792ae608db03c_58game. Okay, so go into ViewController.h
Segment details
3:09–3:11 · rev_57470d71da7371197d4792ae608db03c_59and under interface do open curly
Segment details
3:12–3:15 · rev_57470d71da7371197d4792ae608db03c_60brackets, close curly brackets, and then
Segment details
3:15–3:18 · rev_57470d71da7371197d4792ae608db03c_61IBOutlet UIImage,
Segment details
3:18–3:20 · rev_57470d71da7371197d4792ae608db03c_62and this can be you. And then
Segment details
3:21–3:25 · rev_57470d71da7371197d4792ae608db03c_63the next one for floor So we always put
Segment details
3:25–3:29 · rev_57470d71da7371197d4792ae608db03c_64IBOutlet and then UI, and now because
Segment details
3:29–3:31 · rev_57470d71da7371197d4792ae608db03c_65they're image views, you put ImageView.
Segment details
3:31–3:33 · rev_57470d71da7371197d4792ae608db03c_66If they were labels, you put UILabel. If
Segment details
3:34–3:36 · rev_57470d71da7371197d4792ae608db03c_67it's buttons, put UIButton. So IBOutlet
Segment details
3:37–3:39 · rev_57470d71da7371197d4792ae608db03c_68and then UIButton for the jump button,
Segment details
3:40–3:43 · rev_57470d71da7371197d4792ae608db03c_69asterisk, and just call it whatever you
Segment details
3:43–3:45 · rev_57470d71da7371197d4792ae608db03c_70want— jump, whatever, doesn't really
Segment details
3:45–3:46 · rev_57470d71da7371197d4792ae608db03c_71matter as long as it's easy to remember
Segment details
3:47–3:49 · rev_57470d71da7371197d4792ae608db03c_72for you. Now we need an integer. So
Segment details
3:49–3:53 · rev_57470d71da7371197d4792ae608db03c_73integers and bools go under import. We
Segment details
3:53–3:55 · rev_57470d71da7371197d4792ae608db03c_74need an integer for the jump, jump value,
Segment details
3:56–3:58 · rev_57470d71da7371197d4792ae608db03c_75so let's just call it jumpValue.
Segment details
3:59–4:01 · rev_57470d71da7371197d4792ae608db03c_76And then we also need an IBAction for the
Segment details
4:03–4:07 · rev_57470d71da7371197d4792ae608db03c_77jump button. IBAction is just where you
Segment details
4:07–4:11 · rev_57470d71da7371197d4792ae608db03c_78put the code for the button so that when
Segment details
4:11–4:13 · rev_57470d71da7371197d4792ae608db03c_79you press the button, this code will run.
Segment details
4:14–4:15 · rev_57470d71da7371197d4792ae608db03c_80Let's call it jumpCode.
Segment details
4:15–4:17 · rev_57470d71da7371197d4792ae608db03c_81And we also need a timer so that when the
Segment details
4:19–4:23 · rev_57470d71da7371197d4792ae608db03c_82character goes up in the air, he falls
Segment details
4:23–4:25 · rev_57470d71da7371197d4792ae608db03c_83back down to the ground. So we'll call it
Segment details
4:25–4:27 · rev_57470d71da7371197d4792ae608db03c_84NSTimer and asterisk, and we'll call
Segment details
4:27–4:31 · rev_57470d71da7371197d4792ae608db03c_85it fallingTimer.
Segment details
4:31–4:33 · rev_57470d71da7371197d4792ae608db03c_86And then we need a void as well for the
Segment details
4:37–4:39 · rev_57470d71da7371197d4792ae608db03c_87timer, and we'll call it fallingCode.
Segment details
4:39–4:42 · rev_57470d71da7371197d4792ae608db03c_88So I think we're all done. Now we need to
Segment details
4:44–4:47 · rev_57470d71da7371197d4792ae608db03c_89link up these, uh, what are they called,
Segment details
4:47–4:50 · rev_57470d71da7371197d4792ae608db03c_90thingies, the buttons and stuff. So we
Segment details
4:50–4:54 · rev_57470d71da7371197d4792ae608db03c_91have the floor on outlets, drag it onto
Segment details
4:54–4:57 · rev_57470d71da7371197d4792ae608db03c_92the floor, and you, drag it onto you,
Segment details
4:57–5:00 · rev_57470d71da7371197d4792ae608db03c_93and jump, we'll drag that onto the jump
Segment details
5:01–5:04 · rev_57470d71da7371197d4792ae608db03c_94button. And then the actions, received
Segment details
5:04–5:06 · rev_57470d71da7371197d4792ae608db03c_95actions, jump code. Go on to
Segment details
5:07–5:10 · rev_57470d71da7371197d4792ae608db03c_96jump and do touchUpInside. That just means
Segment details
5:11–5:13 · rev_57470d71da7371197d4792ae608db03c_97that the code will run after you've
Segment details
5:13–5:17 · rev_57470d71da7371197d4792ae608db03c_98pressed it and then let go of pressing it.
Segment details
5:17–5:19 · rev_57470d71da7371197d4792ae608db03c_99So then we go to ViewController.m
Segment details
5:21–5:24 · rev_57470d71da7371197d4792ae608db03c_100and we have to do our timer. So we want
Segment details
5:25–5:27 · rev_57470d71da7371197d4792ae608db03c_101the timer to run as soon as the game
Segment details
5:27–5:28 · rev_57470d71da7371197d4792ae608db03c_102launches, so put it in viewDidLoad. Now
Segment details
5:29–5:31 · rev_57470d71da7371197d4792ae608db03c_103our timer is called fallingTimer equals
Segment details
5:31–5:32 · rev_57470d71da7371197d4792ae608db03c_104square bracket, NSTimer scheduled,
Segment details
5:35–5:38 · rev_57470d71da7371197d4792ae608db03c_105and it will be the second one down with
Segment details
5:39–5:41 · rev_57470d71da7371197d4792ae608db03c_106target, TimeInterval 0.05, target self,
Segment details
5:41–5:45 · rev_57470d71da7371197d4792ae608db03c_107selector @selector, and in the brackets
Segment details
5:45–5:49 · rev_57470d71da7371197d4792ae608db03c_108we put the void name which was
Segment details
5:49–5:51 · rev_57470d71da7371197d4792ae608db03c_109forwardingCode. And then userInfo should
Segment details
5:51–5:55 · rev_57470d71da7371197d4792ae608db03c_110be nil, repeats yes, and then semicolon.
Segment details
5:55–5:58 · rev_57470d71da7371197d4792ae608db03c_111Okay, so now we need to do the void for
Segment details
5:59–6:03 · rev_57470d71da7371197d4792ae608db03c_112the falling— what was it— falling code,
Segment details
6:03–6:06 · rev_57470d71da7371197d4792ae608db03c_113and then open curly brackets. Now this is
Segment details
6:07–6:11 · rev_57470d71da7371197d4792ae608db03c_114for the
Segment details
6:11–6:16 · rev_57470d71da7371197d4792ae608db03c_115movement for the falling movement,
Segment details
6:16–6:19 · rev_57470d71da7371197d4792ae608db03c_116so we do u.center CGPoint.make
Segment details
6:19–6:26 · rev_57470d71da7371197d4792ae608db03c_117u.center.x. Now falling is going to be
Segment details
6:30–6:32 · rev_57470d71da7371197d4792ae608db03c_118u.center.y, but instead of putting a
Segment details
6:33–6:34 · rev_57470d71da7371197d4792ae608db03c_119number, we're going to put minus
Segment details
6:35–6:36 · rev_57470d71da7371197d4792ae608db03c_120jumpValue. And jumpValue
Segment details
6:36–6:41 · rev_57470d71da7371197d4792ae608db03c_121is going to be jumpValue equals jumpValue
Segment details
6:41–6:45 · rev_57470d71da7371197d4792ae608db03c_122minus 5. So it should
Segment details
6:45–6:49 · rev_57470d71da7371197d4792ae608db03c_123be falling by -5 every time it this timer
Segment details
6:50–6:53 · rev_57470d71da7371197d4792ae608db03c_124is running. So we can test it out, just
Segment details
6:54–6:55 · rev_57470d71da7371197d4792ae608db03c_125put it at the top, see if it falls down.
Segment details
6:55–6:56 · rev_57470d71da7371197d4792ae608db03c_126It might fall up, I'm not sure. I get
Segment details
6:57–6:59 · rev_57470d71da7371197d4792ae608db03c_127confused with minus and plus sometimes.
Segment details
7:00–7:01 · rev_57470d71da7371197d4792ae608db03c_128Where is it? So it takes some time to
Segment details
7:08–7:11 · rev_57470d71da7371197d4792ae608db03c_129open. Where is it? There we go. So it's
Segment details
7:11–7:14 · rev_57470d71da7371197d4792ae608db03c_130just fallen, but what we want it to do is
Segment details
7:14–7:16 · rev_57470d71da7371197d4792ae608db03c_131when it hits the floor We want it to stop
Segment details
7:17–7:19 · rev_57470d71da7371197d4792ae608db03c_132falling, so we do if CGRect intersectsRect
Segment details
7:19–7:24 · rev_57470d71da7371197d4792ae608db03c_133, and then— so
Segment details
7:27–7:31 · rev_57470d71da7371197d4792ae608db03c_134what do we want to do? jumpValue equals 0.
Segment details
7:31–7:35 · rev_57470d71da7371197d4792ae608db03c_135Let's see what happens now. Now it's
Segment details
7:35–7:38 · rev_57470d71da7371197d4792ae608db03c_136probably going to stop falling, and then
Segment details
7:39–7:40 · rev_57470d71da7371197d4792ae608db03c_137it's going to get stuck in the floor.
Segment details
7:41–7:42 · rev_57470d71da7371197d4792ae608db03c_138Yeah, it just gets stuck in the floor,
Segment details
7:43–7:44 · rev_57470d71da7371197d4792ae608db03c_139but it keeps going down for some reason.
Segment details
7:44–7:46 · rev_57470d71da7371197d4792ae608db03c_140So we'll also put— make it so the
Segment details
7:47–7:50 · rev_57470d71da7371197d4792ae608db03c_141character appears at the top of the floor.
Segment details
7:51–7:52 · rev_57470d71da7371197d4792ae608db03c_142u.center CGPoint.make .
Segment details
7:53–8:00 · rev_57470d71da7371197d4792ae608db03c_143Now we don't want it to appear at the
Segment details
8:01–8:02 · rev_57470d71da7371197d4792ae608db03c_144center of the floor, we want it to appear
Segment details
8:03–8:04 · rev_57470d71da7371197d4792ae608db03c_145at the top of the floor. So I'm not sure
Segment details
8:04–8:07 · rev_57470d71da7371197d4792ae608db03c_146what the correct number would be, so it
Segment details
8:07–8:09 · rev_57470d71da7371197d4792ae608db03c_147might be something like -50. Just test
Segment details
8:09–8:13 · rev_57470d71da7371197d4792ae608db03c_148So it's still a bit too high, so let's try
Segment details
8:17–8:20 · rev_57470d71da7371197d4792ae608db03c_149-70.
Segment details
8:20–8:20 · rev_57470d71da7371197d4792ae608db03c_150That's about right. Try 75, just so
Segment details
8:26–8:30 · rev_57470d71da7371197d4792ae608db03c_151it looks like he's on top of the floor,
Segment details
8:30–8:31 · rev_57470d71da7371197d4792ae608db03c_152not inside of the floor. Okay, now that's
Segment details
8:31–8:35 · rev_57470d71da7371197d4792ae608db03c_153too high, so it keeps bouncing him back
Segment details
8:35–8:37 · rev_57470d71da7371197d4792ae608db03c_154up. It's kind of funny actually. Try 71.
Segment details
8:38–8:40 · rev_57470d71da7371197d4792ae608db03c_155Okay, so he's like hovering slightly.
Segment details
8:45–8:47 · rev_57470d71da7371197d4792ae608db03c_156Okay, now we do need to do the jump
Segment details
8:48–8:50 · rev_57470d71da7371197d4792ae608db03c_157button. So we do IBAction jump,
Segment details
8:50–8:54 · rev_57470d71da7371197d4792ae608db03c_158jumpCode. Get rid of this extra sender and
Segment details
8:55–9:00 · rev_57470d71da7371197d4792ae608db03c_159then do open curly brackets. Now we want
Segment details
9:00–9:04 · rev_57470d71da7371197d4792ae608db03c_160every time you press the button, we'll put
Segment details
9:04–9:06 · rev_57470d71da7371197d4792ae608db03c_161jumpValue equals 50.
Segment details
9:06–9:11 · rev_57470d71da7371197d4792ae608db03c_162I'm not sure if this is right. Let's just
Segment details
9:12–9:14 · rev_57470d71da7371197d4792ae608db03c_163test it out. Okay, yeah, that's right.
Segment details
9:15–9:19 · rev_57470d71da7371197d4792ae608db03c_164So that's it, we've done— we've made a
Segment details
9:20–9:22 · rev_57470d71da7371197d4792ae608db03c_165jump button. He jumps. If you keep
Segment details
9:22–9:24 · rev_57470d71da7371197d4792ae608db03c_166pressing it, he keeps jumping up, and then
Segment details
9:24–9:26 · rev_57470d71da7371197d4792ae608db03c_167he falls faster and faster. So if you keep
Segment details
9:26–9:28 · rev_57470d71da7371197d4792ae608db03c_168making him go really high, he ends up
Segment details
9:29–9:30 · rev_57470d71da7371197d4792ae608db03c_169falling so fast— oh, there we go. Last
Segment details
9:31–9:33 · rev_57470d71da7371197d4792ae608db03c_170time I did this, he fell through the
Segment details
9:33–9:35 · rev_57470d71da7371197d4792ae608db03c_171floor. So that's how you make a platformer
Segment details
9:36–9:40 · rev_57470d71da7371197d4792ae608db03c_172game jump, jump button. Pretty easy,
Segment details
9:40–9:43 · rev_57470d71da7371197d4792ae608db03c_173right? So if you want, you can fiddle
Segment details
9:43–9:46 · rev_57470d71da7371197d4792ae608db03c_174around with these values. You can make it
Segment details
9:46–9:47 · rev_57470d71da7371197d4792ae608db03c_175jump a bit lower, so lower the number and
Segment details
9:48–9:54 · rev_57470d71da7371197d4792ae608db03c_176he'll jump not so high.
Segment details
9:55–9:56 · rev_57470d71da7371197d4792ae608db03c_177If you increase jump value here, he'll
Segment details
9:58–10:02 · rev_57470d71da7371197d4792ae608db03c_178fall faster.
Segment details
10:02–10:03 · rev_57470d71da7371197d4792ae608db03c_179So he falls faster, so he can't jump so
Segment details
10:09–10:11 · rev_57470d71da7371197d4792ae608db03c_180high. So that's it. Hope you learned
Segment details
10:11–10:14 · rev_57470d71da7371197d4792ae608db03c_181something. Hope it wasn't too fast. It's
Segment details
10:14–10:16 · rev_57470d71da7371197d4792ae608db03c_182not really much code. All you need is the
Segment details
10:16–10:18 · rev_57470d71da7371197d4792ae608db03c_183timer, the void, so the timer
Segment details
10:19–10:23 · rev_57470d71da7371197d4792ae608db03c_184runs this code to make him fall down. And
Segment details
10:24–10:27 · rev_57470d71da7371197d4792ae608db03c_185then the jump button— all the jump button
Segment details
10:27–10:29 · rev_57470d71da7371197d4792ae608db03c_186is, you add 35 to the jump value.
Segment details
10:29–10:31 · rev_57470d71da7371197d4792ae608db03c_187And then you need 3 IB outlets: you,
Segment details
10:34–10:37 · rev_57470d71da7371197d4792ae608db03c_188floor, and jump button, and an end timer.
Segment details
10:37–10:40 · rev_57470d71da7371197d4792ae608db03c_189So pretty simple. I guess in the next
Segment details
10:40–10:43 · rev_57470d71da7371197d4792ae608db03c_190lesson we can do— we can build on this.
Segment details
10:43–10:45 · rev_57470d71da7371197d4792ae608db03c_191We can do a left button and a right button
Segment details
10:45–10:48 · rev_57470d71da7371197d4792ae608db03c_192to make him move left to right. So yeah,
Segment details
10:48–10:51 · rev_57470d71da7371197d4792ae608db03c_193look forward to that video, and I'll see
Segment details
10:51–10:53 · rev_57470d71da7371197d4792ae608db03c_194you next time.
Segment details
10:53–10:53 · rev_57470d71da7371197d4792ae608db03c_195