Wednesday, December 17, 2014

How to implement a space shooter with SpriteKit and SWIFT - Part 5: Particles and Sound

Adding particles and sound 




Welcome to part 5 of my tutorial series. In the previous parts we've created a sprite, added movement, created enemies which follow our sprite, added bullets, a HUD, collision detection, .... 
But, for a real game some important elements are missing to beautify the game:
  • Sound effects: explosions, game over, ...
  • Particle effects: explosions, background star field 

I'll show how to implement this today. As a starting point you can download the code from tutorial part 4 here

Thursday, November 27, 2014

How to implement a space shooter with SpriteKit and SWIFT - Part 4: Collision Detection

Adding basic game logic and collision detection





Welcome to part 4 of my tutorial series. In the previous parts we've created a sprite, added movement, created enemies which follow our sprite, added bullets and a HUD. But, for a real game some essential parts are missing:

  • Collision detection between the bullets and our sprite
  • Basic game logic
    • Scoring
    • Pause
    • Life Lost & Game Over

I'll show how to implement this today. As a starting point you can download the code from tutorial part 3 here


Wednesday, November 19, 2014

How to implement a space shooter with SpriteKit and SWIFT - Part 3: Create a HUD

Adding a HUD with SpriteKit and SWIFT





Tutorial Overview:


  • Part 1: Initial project setup, sprite creation and movement using SKAction and SKConstraint
  • Part 2: Adding enemies, bullets and shooting with SKAction and SKConstraint
  • Part 3: Adding a HUD with SKLabelNode and SKSpriteNode
  • Part 4: Adding basic game logic and collision detection
  • Part 5: Adding particles and sound 
  • Part 6: GameCenter integration

Add the HUD:

I'll add a simple HUD which shows the score, the remaining lifes and a pause button. As a starting point you can download the code from tutorial part 2 here

First of all let's fix a bug in the sample code of my last post. Open GameViewController.swift and move the code from viewDidLoad to viewDidAppear. This is necessary because the orientation change to landscape might not be completed. In this case width and height are inverted, if we determine them in viewDidLoad:

Tuesday, November 11, 2014

How to implement a space shooter with SpriteKit and SWIFT - Part 2

Adding enemies, bullets and shooting with SKAction and SKConstraint





Tutorial Overview:

  • Part 1: Initial project setup, sprite creation and movement using SKAction and SKConstraint
  • Part 2: Adding enemies, bullets and shooting with SKAction and SKConstraint
  • Part 3Adding a HUD with SKLabelNode and SKSpriteNode
  • Part 4Adding basic game logic and collision detection
  • Part 5: Adding particles and sound 
  • Part 6: GameCenter integration


Add the enemies:

I'll add several enemy sprites. These will automatically follow and orient to the hero sprite.  You can download the code from Part 1 here.



Wednesday, November 5, 2014

How to implement a space shooter with SpriteKit and SWIFT - Part 1

Initial project setup, sprite creation and movement using SKAction and SKConstraint






Tutorial Overview:

  • Part 1: Initial project setup, sprite creation and movement using SKAction and SKConstraint
  • Part 2: Adding enemies, bullets and shooting with SKAction and SKConstraint
  • Part 3: Adding a HUD with SKLabelNode and SKSpriteNode
  • Part 4: Adding basic game logic and collision detection
  • Part 5: Adding particles and sound 
  • Part 6: GameCenter integration


1. Create a new universal project (template: game; language: Swift)




Tuesday, October 21, 2014

Writing games is more fun than writing a blog post: New teaser video for my upcoming tutorial

Sorry, I love writing blog posts, but this time I have written a small game instead of completing my tutorial. Here's another short teaser video:




That's all for today. The complete code will be available at GitHub soon.

Cheers,
Stefan

Wednesday, October 8, 2014

Kick off for my new Tutorial: How to implement a space shooter with SpriteKit and SWIFT

I'm preparing a new tutorial: 

My goal is to implement a complete space shooter with SpriteKit and SWIFT.

Planned content is:

  • Part 1: Initial project setup, sprite creation and movement using SKAction and SKConstraint
  • Part 2: Adding enemies, bullets and shooting with SKAction and SKConstraint
  • Part 3: Adding a HUD with SKLabelNode and SKSpriteNode
  • Part 4: Adding basic game logic and collision detection
  • Part 5: Adding particles and sound 
  • Part 6: GameCenter integration

Here's a short teaser video:


The sample code will be available on GitHub



That's all for today.

Cheers,
Stefan

Monday, September 22, 2014

HowTo: Implement targeting or follow behavior for sprites with SpriteKit and SKConstraint in SWIFT

Welcome to Part 14 of my blog series about iOS game development.

At the developer conference WWDC, in June this year, Apple showed a new class in SpriteKit: SKConstraint. It can be used to define constraints for the orientation, the distance or the position of SpriteKit nodes. In my todays blog post I'll show how to use SKContraints to implement a follow and targeting behavior. I have updated this tutorial to XCode 6.1!






Thursday, September 18, 2014

How to use an Universal Storyboard in Xcode

Welcome to Part 13 of my blog series about iOS game development.

At the developer conference WWDC, in June this year, Apple showed a nice concept for targeting multiple form factors: The Universal Storyboard. Basically this replaces the iPad and the iPhone specific storyboards  with one universal storyboard. To enable different layouts for tablet and phone form factors it's working closely together with Autolayout and Size Classes.

I'll not explain Autolayout and Size Classes deeply in this post. My main motivation was to find out how to convert an old Xcode project with two storyboards into one universal storyboard. If you start a new project, the universal storyboard will be created by default.

As a start project you can use the MyGame project from my earlier posts. You can download it from GitHub: v0.9 
This sample needs Xcode 6.

Monday, July 21, 2014

How to convert/integrate SWIFT with Objective C

Welcome to Part 12 of my blog series about game development.
Today I'll show how to combine SWIFT with Objective-C code. There is no need to migrate all of your existing code to SWIFT. You’ll not sell one App more, if this is the only improvement of your new version. Not to mention all the possible new bugs you might include during the migration. A better strategy could be developing new code in SWIFT and keep existing code in Objective-C.

Prerequisite is XCode 6.1!

I've moved my blog to a new address: http://developerplayground.net
An updated version of this article for XCode 6.3 and SWIFT 1.2 can be found in my main Blog here.


I’ll show two scenarios:
  • calling SWIFT from Objective-C
  • calling Objective-C from SWIFT


Wednesday, July 2, 2014

WWDC and SWIFT

Welcome to Part 11 of my blog series about game development.


I've been busy the last weeks with watching WWDC videos. So much new stuff and so little time ;-). 

My favorites are Swift, Playground, Sprite Kit enhancements like the new level editor and especially this new Interface Builder Feature: It is possible to use ONE Storyboard to target both: iPad and iPhone/iPod.

Luckily Apple lifted the NDA a little bit, so it's allowed to talk about the new stuff.

But step by step...

First of all I'm planning to implement new parts of my game in SWIFT! 

What does this mean? 

One of the first things I've to figure out is how to call Objective C code from SWIFT and vice versa. I'll show this in one of my next posts.

Why?

Writing this Blog and implementing a game is one of my hobbies. I've no intention to earn money with it. Learning new things means fun for me. I just WANT to learn SWIFT. Maybe I would have taken a complete different decision in my job.

Where to start?

A good starting point to learn Swift is the official documentation from Apple. The iBooks version is available hereIf you just want to have a quick start with SWIFT you can use this Cheat Sheet, provided by Ray Wenderlich. You can also find some SWIFT tutorials on his website.



That's all for today. I want to complete the WWDC video about 'What's new in SpritKit'. In my next post I'll show how to combine SWIFT with Objective C.


Cheers,
Stefan

Thursday, June 12, 2014

HowTo: Implement a Delegate Pattern to communicate between a SpriteKit Scene and the parent ViewController

Welcome to Part 10 of my blog series about game development.


Today I'll show how to use a delegate pattern to communicate with the ViewController which contains our Scene. You can download the project from GitHub: v0.7 if you haven't completed part 8.

One of the most important characteristics of this pattern is 'Inversion of control'. The goal of this principle is to remove dependencies between objects. The main idea is that a 'delegator' object 'delegates' the execution a task to a 'delegate object'. You can find multiple definitions and tutorials about the Delegate Pattern. Therefore I'll not explain the pattern itself, but show how you can use it for the following Situation:



After creating a new SpriteKit project you typically have a ViewController which has a reference to a SKScene object:

The ViewController presents the screen and starts the game. This works fine as long as the game lasts. But what can you do, if the game is over?

Wednesday, May 28, 2014

HowTo organize your Objective code with the '#pragma mark' directive


Welcome to Part 9 of my blog series about game development.


Todays post is very short. I'll only show how the '#pragma mark' directive can help you to organize your code. The navigation bar on top of the code window provides the possibility to navigate in your code. Just click on the last entry:




This will open a drop down list of all available constants, properties and methods. By selecting one element in the list, the code windows scrolls to the corresponding code section. So far so good, but  the methods are listed in alphabetical order. This becomes quite messy if the code for your class is growing.

Thursday, May 22, 2014

HowTo: Implement a HUD in SpriteKit

Welcome to Part 8 of my blog series about game development.




Today I'll add a HUD (head up display) to the SpriteKit Scene. The HUD shows the remaining lives, current, level, score and has the option to pause the game:





Create the HUD:

1. Create a new SpritKit project in Xcode:
















Monday, May 5, 2014

HowTo: Extend endless horizontal scrolling with a vertical parallax effect

Welcome to Part 7 of my blog series about game development.

Today I'll extend the parallax effect from part 5 of my posts with vertical scrolling. This should increase the illusion of depth. To control the movement I'll use the motion sensors as described in part 6.

Steps to achieve this behavior:


  • Scale the width and the height of the background image and implement horizontal and vertical movement of the background image:







Monday, April 7, 2014

HowTo: Use the Device Motion Sensors to control your game


Welcome to Part 6 of my blog series about game development.


Today I'll include motion detection to control the movement of my game. iOS offers a powerful API to handle motion detection with the CMMotionManager class.

Let's start with a small standalone project to show how to use the motion detection:

Friday, March 28, 2014

HowTo: Implement endless scrolling with parallax effects

Welcome to Part 5 of my blog series about game development.

Today I'll create a component which implements the endless scrolling and adds some parallax effects. I'll use SpriteKit for that. A nice tutorial about SpriteKit can be found here and here and here.

If you haven't completed part 3 or 4, you can download the project from GitHub: v0.3

First of all we need some background images to show the infinite parallax scrolling. I've created four layers:

Background:





Tuesday, March 18, 2014

HowTo: Implement endless scrolling


Welcome to Part 4 of my blog series about game development.

Today I'm showing how to implement an endless scrolling which is typical for Jump & Run games. 




First of all you need a background with 3 sections like the one shown below:



Section 1 and 3 must be identical and have to fit on the whole screen. 


Tuesday, March 4, 2014

HowTo: Add Splash Screen & Application Icons

Welcome to Part 3 of my blog series about game development.

Today I'm adding the app icons and a splash screen. I'll use an asset catalog for that. If you haven't completed part 2, you can download the project from GitHub: v0.2.1

First of all let's hide the annoying header bar:




You have to add to entries in the plist file: "Supporting Files/MyFirstGame-Info.plist"

Wednesday, February 19, 2014

HowTo: Add View Controllers to the game storyboard and use segues to navigate between them

Welcome to Part 2 of my blog series about game development.


Today I'm creating the basic game infrastructure, not the game itself. If you haven't completed part 1, you can download the project from GitHub (version v0.1).


Basic screens needed for the game:



  • Start Screen: Main menue 
  • About Screen: Information about the developer of the game, website, ...
  • Settings Screen: Choose settings like Sound on/off, ...
  • Play Screen: The Game
  • AddHighScoreScreen: Add a new highscore entry
  • Highscore: List of the highscores 

Monday, February 10, 2014

HowTo: Design for depth - Creating a start screen with parallax animations using iOS 7 motion effects


One highly noticed innovation in iOS 7 was the parallax effect on the home screen. When you tilt your device this gives you the impression of depth.

Luckily it is incredible easy to implement this behaviour with the iOS 7 motion effects.

First you need a background which is larger than the screen and some foreground elements like Buttons, Labels, ...:



Thursday, February 6, 2014

Kick Off - Creating a Jump & Run game for iOS Devices


I love developing small games and did this on multiple platforms ...

... but no one has ever been really finished. The reasons have been every time the same: Not good enough, I didn't know how to distribute, no time to continue, ...

After buying my first iPhone and Mac I decided to learn Objective C. In my opinion the best way to learn new things is having fun. So I started writing a small game prototype. Without experience in Objective C and at the beginning not knowing where to go, I ended up with a running prototype and a lot of spaghetti code.
Now having a clear goal and a lot more experience on the iOS platform I decided to do a complete redesign.

To motivate me additionally I'll share the progress and my learnings in this blog.

Please be patient with me, if I need some time to post new updates. Being a father of two little girls means I have not more than one or two hours in the evening to work on this game (of course not every evening).

Let's see if I can finish it this time ;-)
Have fun!

Stefan


Planned Topics:

  • Create the skeleton app: Views, Storyboards, UIView Animations
  • View Controller Navigation
  • HighScore
    • TableView
    • Picture Capturing
  • Import tmc level files from Tiled
  • Use URL Schemes to import tmc files send per email
  • SpriteKit
    • Physics
    • Animation
    • Handling collisions
    • Use CoreMotion
    • ...
  • Use Apple TV to play on a big screen
  • Game Center integration
  • iAd integration