in Swift

Bouncing Soccer Balls in Swift

soccer_ball

Nothing fancy, nothing complicated, just a simple sample of some bouncing soccer balls in Swift. To start off, create a simple OSX Application under New::Projects. Under OS-X choose game

 

 

 

Screen Shot 2014-07-16 at 7.29.34 PM

Then on the next screen add a product name, and choose “Swift” as the language. And for Organization Identifier, the usual com.yourname. syntax.

Screen Shot 2014-07-16 at 7.29.22 PM

When you hit next, Xcode will create a game project for you. Go and click on the GameScene.swift file and let it open up on the editor.

Replace the source with the following source code.

Add the soccer ball image (named soccer_ball.png) Drag and drop it into the folder created on the top level as yourGameScene.swift and as shown on the following image.

Screen Shot 2014-07-16 at 7.32.36 PM

(If you want the soccer ball, the easiest thing that you can do is right click on the soccer ball at the top of the blog, choose Open Image in New Tab, and then on the new tab, drag it to your folder or desktop and then add it to the project via drag and drop and you should end like the image above).

Here is a short video of how it should end up looking like.

Let me know what you think, and enjoy.

Carlos

Write a Comment

Comment

 

  1. Very cool, Carlos. A couple things I worked through to get it going…

    • During the new project wizard, you must set Game Technology to SpriteKit

    • Since typecasting in Swift seems to be an incomplete feature, using a later version of Xcode 6 (6A267n) – I think they call it Beta 4 – line 20 would not compile until I changed it to this:
    var xx = CGFloat ( UInt(arc4random()) % UInt(self.view.frame.size.width))