How To Make a Simple iPhone Game with Flash CS5

This is a tutorial by iOS Tutorial Team member Russell Savage, the founder of Dented Pixel, a creative development company. He recently released its first app – Princess Piano – and he is currently hard at work on several new projects. I originally got into Objective C reluctantly. I had been holding out because I […] By Ray Wenderlich.

Leave a rating/review
Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Pickups

Now let’s add some gold coins for you to pickup. First we have to create the gold coin, using the same technique we used to create the puck and paddle, I am going to name it “PickupGood”.

Creating a good pickup

Now let’s create the code that randomly distributes this item.

var pickupGood:Sprite;
   	 
private function addPickupGood(){
    var edgePadding:Number = stage.stageWidth/40;
    pickupGood = new PickupGood() as Sprite;
    pickupGood.x = Math.random() * (stage.stageWidth-edgePadding) + edgePadding;
    pickupGood.y = Math.random() * (stage.stageHeight-edgePadding) + edgePadding;
    this.addChild( pickupGood );
}

Then add this line to the constructor to add the pickup the first time:

addPickupGood();

Now we need to add the hit detection code for the pickups. Add this code in the update function:

// Hit detection for pickups
if( hockeyPuck.hitTestObject( pickupGood ) ){
    // increase the score
    levelScore++;
    currentScore.text = String(levelScore);
    currentScore.setTextFormat( new TextFormat("Arial", stage.stageWidth * 0.1, 0x000000, "bold") );
   			 
    // remove this pickup from the screen
    this.removeChild( pickupGood );
    pickupGood = null;
   			 
    // add a new pickup
    addPickupGood();
}

This code checks if the puck has hit the pickup. If it does it increases the score, as well as spawning a new pickup.

Guess what - you're done! Hit Command+Enter to see the final game result:

The final simple iPhone game made in Flash CS5.5!

Where To Go From Here?

Here is the final example project with all of the code from the above tutorial.

Congratulations, you now know the basics of developing a simple iPhone game with Flash CS5.5!

Here's some great resources to learn more about Flash from here:

Hope you enjoy playing around with Flash, and I hope to see some Flash-developed games from you guys in the App Store! In the meantime, if you have any questions about Flash CS 5 for iPhone development or comments or questions on this tutorial, please join the forum discussion below!

This is a tutorial by iOS Tutorial Team member Russell Savage, the founder of Dented Pixel, a creative development company. He recently released its first app - Princess Piano - and he is currently hard at work on several new projects.

Contributors

Over 300 content creators. Join our team.