iOS Swift Game Tutorial: SpriteKit Space Game (with Explosions)

In this tutorial you are going to create a SpriteKit Space Game that uses particle emitters for an animated star field and explosions. You are also going to use the iPhones accelerometer to move your player on the screen.

Check out Part 2:
You are going to add a menu, the player is going to get lives and you are going to learn how to work with multiple SpriteKit scenes.




If you have questions about the video or Cocoa programming, please comment below.


EpicGifted says:

Why did you shuffle the entire array of strings instead of picking a random number from 0 to 2 and indexing into the array? Shuffling strings randomly will increase the number of computational instructions required, putting an unnecessarily high burden on the battery life of the phone.

Jack Geraghty says:

Plz help iy says hello world when i run it….

Paul David Serafin says:

Hi. Thanks for the tutorial; very interesting and everything works fine for me. I was just thinking that in would be nice if the player (starship) could bounce off the edge of the screen and change direction instead of dissapearing and appearing on the other side. I tried but i can’t figure out how to make the player node interact (maybe with an impulse or a force) when it hits the edge of the screen. Tahank you.

Professor Finesser says:

got it finished and running on my device, this is a great tutorial

Jesse Peeters says:

I have a problem with the starfield. when I run the app it shut down and I get a error called:
starfield.position = CGPoint(x: 0, y: 1472) thread 1: EXC_BAD_INSTRUCTION(code=EXC_l386_INVOP, subcode=0x0)

somebody a solution? Thanks!

Prexto Rex says:

Ive got a massive “Hello World” in the middle of the screen. How do I get rid of that??

ItsGabi says:

my text isn’t showing up & my aliens are all stuck on the right side of the screen.

MedoMan says:

Can u do a video we’re you show us how to add multiple sprites in sprite kit

Benjamin Rosenfeld says:

brian can you please do all the features matt did. I love your work much better and I think theres still lots more you could add to this game Please p.s i subbed

Daniel Lobato says:

Spark png is not created when the action is created help.

lKawerMusic says:

Hey, great video. I just have the problem that my game does not end, even if I hit a planet or alien. Anyone has an idea on how to fix this? Thanks!

Benjamin Rosenfeld says:

Hi brian love the video, Can you make an update to this on how to add lives so when an asteroid hits the ship you lose 1 of 3 andhow to add a high score, this game is really cool many thanks benjamin.

Shahrose Mohsin says:

Hey man,

My name is Shahrose Mohsin and a CS major who only completed one intro course so far. I am really into app building especially with swift I discovered.

How did you learn this language? I

If you can give me any tips on to speed my learning process, it would be great.

I want to work as a app developer for a company and make apps on the side!

Julio Ryuuzaki says:

Really would love to see more that can be done with the Watch

land ho says:

particle file won’t work.mine is saying SpriteKit document version is newer than supported. please help!

naiem salib says:

Hey Brian i keep getting this error on the calling of the torrpedoDidCollideWithAlien function ,

fatal error: unexpectedly found nil while unwrapping an Optional value

Nathan Pavlovsky says:

Hello, and thanks for a wonderful tutorial!

Quick question – why do your image assets come in @2x and @3x in your project on github but not @1x? Is there a certain reason why?

Ishaaq says:

How did you make your intro? did someone make it for you? I need to know!!

Jayven says:

what the heck is a 0x1 << 1, also I am not too clear about the purpose of the category and what it does

Cường Trần says:

Hi guy
You can make tutorial about chat messages of web Use API of
Thanks you very much

Kevin Berot says:

Hey Brian, I am having the same issue as @slither… My shuttle is stuck on the right side of the screen. Anyone knows how to fix that? Thanks!

Yohan Toro says:

Hi brian i get an error ” argument of ‘#selector’ cannot refer to local function ‘addalien()’ any idea how to fix this ?

Mohammed Araby says:

Thanks for this TUTORIAL , Now i understand how spriteKit work …nice work mate

Khal Drogo says:

If anyone has issues with the emmitter nodes not initializing. First of all make sure that you have NOT selected integrate Gameplay kit when starting the project and second. If you cant see the starfield in the background, either it is under the hello world title OR the gamescene.sks file is not hooked up properly. Just a heads up, spend like 3 hours figuring this out lol

Remy Rima says:

I dont have an Iphone is there a way to test if the spaceships moves when you tilt the device

Vaio Heo says:

Excuse me, can you help me please!
I have a problem in swift, how can I download a file.mp3 on google drive in my ios app, I tried about 1 month but I’ve not found solution. I hope you will help me.
Thank you so much!

Hey Akron says:

I keep getting “can’t assign value type CGPoint to SKEmitterNode!” right after “starfield =”

PawPomb says:

My didBegin(_ contact) method isn’t being called at all

Jack Geraghty says:

how do i set the anchor point??? sorry for the trouble. I am not even old enough for dev program.

pitmanra says:

Brian, thanks for the tutorial. Maybe sometime you’d do a bit on radialgravityfield?

Patriot Gamerz says:

I opened the app to test it on my device but it just showed a grayish black screen. That was after I cut the “Hello World!” text out of the Game Scene. Please tell me what I’m doing wrong.

jimmy Ryan says:

Hey. I just wanted to check, this is the first video in your swift playlist. It doesn’t seem like it should be the first video.

Helen Peng says:

my aliens are moving so slowly, what is wrong with them?

Сергей С says:

Hi, Brian. Can you say what simulator are you using?

George Alegre says:

This was pretty cool. I have been trying to get into iOS development for the past few months and your channel really has helped me. Thanks a lot!

la.den.stå says:

I have this problem where my torpedo bullets sometimes just fly through the aliens, and nothing happens, and sometimes explode and the score increases with 5 points. Any ideas on what the problem could be?

alengqvist says:

Hey Brian, could you please do a guide on how to implement Apples Maps applications favourites view. The one which is draggable and has three states (stick to bottom, middle or top).

Huy iMarketer says:

I load success starfield on phone screen, but i can’t see shuttle when i load it. Can you help ?? Plzzz. Many Thanks

Jack Geraghty says:

Why is the shuttle on the right side of my screen?

Ruben Lago Lopez says:

how can i put the iPhone D?

Allen Wang says:

Where the Apple Watch Version link?

zGibsonLes Paul says:

None of the positions worked in Xcode 9 and iOS 11.

The Mexican Guy says:

+BrianAdvent Hey Brian Amazing tutorial! I did in in one siting! I kind of had to play with the position of the label the ship and the aliens but man, the fact that it was so easy to do, I am sure it is because the code is a well made and simple code! Thanks a lot man!
P.D. I wanted to add a while loop to run only for a minute, allowing the user to play within the loop (and also display the time left) if any one has any idea, help would be much appreciated.

Shahrose Mohsin says:

hey can someone help. when I’m adding in the alien function:

” func addAlien () {
possibleAliens = GKRandomSource.sharedRandom().arrayByShufflingObjects(in: possibleAliens) as! [String]

let alien = SKSpriteNode(imageNamed: possibleAliens)”

the two functions say the following error:

“cannot convert value of type (String,String,String) to expected argument type [Any] / [String]”

Please help.

Write a comment


Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.

Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!

Send this to a friend

▷ Other ReviewsVehicles▷ Show Cars▷ Motorbikes▷ Scooters▷ Bicycles▷ Rims & Tires▷ Luxury BoatsFashion▷ Sunglasses▷ Luxury Watches▷ Luxury Purses▷ Jeans Wear▷ High Heels▷ Kinis Swimwear▷ Perfumes▷ Jewellery▷ Cosmetics▷ Shaving Helpers▷ Fashion HatsFooding▷ Chef Club▷ Fooding Helpers▷ Coktails & LiquorsSports▷ Sport Shoes▷ Fitness & Detox▷ Golf Gear▷ Racquets▷ Hiking & Trek Gear▷ Diving Equipment▷ Ski Gear▷ Snowboards▷ Surf Boards▷ Rollers & SkatesEntertainment▷ DIY Guides▷ Zik Instruments▷ Published Books▷ Music Albums▷ Cine Movies▷ Trading Helpers▷ Make Money▷ Fishing Equipment▷ Paintball Supplies▷ Trading Card Games▷ Telescopes▷ Knives▷ VapesHigh Tech▷ Flat Screens▷ Tech Devices▷ Camera Lenses▷ Audio HiFi▷ Printers▷ USB Devices▷ PC Hardware▷ Network Gear▷ Cloud Servers▷ Software Helpers▷ Programmer Helpers▷ Mobile Apps▷ Hearing AidsHome▷ Home Furniture▷ Home Appliances▷ Tools Workshop▷ Beddings▷ Floor Layings▷ Barbecues▷ Aquarium Gear▷ Safe Boxes▷ Office Supplies▷ Security Locks▷ Cleaning ProductsKids▷ Baby Strollers▷ Child Car Seats▷ Remote ControlledTravel▷ Luggages & Bags▷ Airlines Seats▷ Hotel Rooms▷ Fun Trips▷ Cruise Ships▷ Mexico Tours