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 here. If 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: