Some pictures from the iPhone 4 release event in Shadyside, PA.
The Cocos2d-iPhone website just posted an article on the samples that come with Cocos2d. This is probably THE best resource that a developer can have at their disposal. If you are using Cocos2d on the iPhone you definitely need to check out the sample code that comes with it.
Here is the link to the tutorial.
Version 0.99 of Cocos2d for the iPhone was just released this week. I am using the Cocos2d framework in my game, and wanted to post a short tutorial/sample code for the CocosDenshion sound engine that is shipping with the latest version.
I am going to start off with the the basic Hello World example that is created for you when you create a new Cocos2d project.
In the HelloWorld.h file add the following lines of code to import the needed files:
#import "SimpleAudioEngine.h"
#import "CocosDenshion.h"
#import "CDAudioManager.h"
Now we will move to the HelloWorld.m file to add the rest of the code. Inside the init method will will preload the background music so there is no lag when opening this layer. Since we only have one layer, it makes no difference. This will help when you have multiple layers in a game. One thing to note, the backgroundMusicVolume can be set from the range of 0.0 to 1.0. If you load a new background music file, you will need to set this again.
SimpleAudioEngine *sae = [SimpleAudioEngine sharedEngine];
if (sae != nil) {
[sae preloadBackgroundMusic:@"mario-theme.mp3"];
if (sae.willPlayBackgroundMusic) {
sae.backgroundMusicVolume = 0.5f;
}
}
To play the background sound and other sounds use the following code:
// Start the background music from the beginning and stop the background music
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"mario-theme.mp3"];
[[SimpleAudioEngine sharedEngine] stopBackgroundMusic];
// Mute and unmute all sounds
[CDAudioManager sharedManager].mute = TRUE;
[CDAudioManager sharedManager].mute = FALSE;
// Pause and unpause the background music
[[SimpleAudioEngine sharedEngine] pauseBackgroundMusic];
[[SimpleAudioEngine sharedEngine] resumeBackgroundMusic];
As you can see, CocosDenshion is very simple and easy to use. More information on it can be found here.
If you would like to see this in working action, then head on over to my github repository and download the sample project.
http://github.com/ndubbs/CocosDenshion-Example
As always, comments are welcomed and greatly appreciated.
The update for DC Traffic Cams was approved by Apple and is now available in the iTunes App Store. In this update, I added an error message when the traffic camera images are unavailable. I also added a brief snippet of text to the info screen explaining why the images might not be available and a link to the DC Department of Transportation.
The Issue:
Over the past weekend I found out why I was getting bad reviews for DC Traffic Cams in the App Store. The source from where the camera images are being downloaded from was not delivering images. If you view Washington DC’s department of transportation website, they were having the same issue. I also took a look at my competitors’ apps and they fell prey to the same issue.
The Big Problem:
I in no way shape or form was informing the app user of what was going on. This was a big mistake on my part. In an effort to alleviate the issue, I have been working on a solution and will be submitting an update very soon. This will at least let the user know that the app is working but there is no image to display, versus just displaying a blank screen.
Over the past month, I have been looking at every tutorial and sample code that I could get my hands on regarding cocos2d on the iPhone. This past week I came across some professor’s wordpress blog for his class. One of the lectures was on cocos2d. Have a look at it. I went through the example code and used some mario graphics I found on the web to come up with my own game level. I’m currently in the process of adding a character and some kind of control mechanism to move it around on the level (beyond the scope of the lecture).

Do you have a good website or tutorial? Please let me know.
I’m taking a break from posting iPhone development code this week. At work I was implementing a cascading drop down list and ran into a few issues. You figure you could watch the tutorials on asp.net’s website and everything would work. Wrong! I am using the dropdownlist control in a form view on the aspx page with binding, so anytime you would submit the form it would spit out an “Invalid postback or callback argument” error. Some suggestions posted on various web pages, blogs, and message boards say to disable EventValidation on the page. What? This is WRONG, WRONG, WRONG! This will bypass all the security was built in to protect against injection attacks. As one of my college professors would always say: “bad dog!”
What you really want to do is register all of the possible values for each dropdownlist. Where can you do this? You have to overriding the Render sub procedure in the code behind file. Here is sample code to fix this issue:
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
If (Me.FormView1.CurrentMode = DetailsViewMode.Insert) Then
Dim ddl1 As DropDownList = CType(Me.FormView1.FindControl("ddlDepartment"), DropDownList)
Dim ddl2 As DropDownList = CType(Me.FormView1.FindControl("ddlEquipment"), DropDownList)
'Load the data from the Departments table into the dropdownlist control for validation
Dim departmentsAdapter As New DepartmentsTableAdapter
For Each row As DataRow In departmentsAdapter.GetDepartments
Page.ClientScript.RegisterForEventValidation(ddl1.UniqueID, _
Trim(row("DepartmentName").ToString()))
Next
'Load the data from the Equipment table into the dropdownlist control for validation
Dim equipmentAdapter As New EquipmentTableAdapter
For Each row As DataRow In equipmentAdapter.GetAllEquipment
Page.ClientScript.RegisterForEventValidation(ddl2.UniqueID, _
Trim(row("EquipmentName").ToString()))
Next
End If
MyBase.Render(writer)
End Sub
I also needed to add required field validators to the drop down lists. This will make sure the user actually selects a value. To do this was pretty simple, you just need to set the InitialValue equal to “”. See the sample code below:
<cc1:CascadingDropDown ID="CascadingDropDown1"
runat="server"
Category="Department"
LoadingText="Loading..."
PromptText="Select a Department"
TargetControlID="ddlDepartment"
ServiceMethod="GetDepartments"
ServicePath="EquipmentService.asmx">
</cc1:CascadingDropDown>
<cc1:CascadingDropDown ID="CascadingDropDown2"
runat="server"
Category="Equipment"
LoadingText="Loading..."
PromptText="Select Equipment"
ParentControlID="ddlDepartment"
TargetControlID="ddlEquipment"
ServiceMethod="GetEquipment"
ServicePath="EquipmentService.asmx">
</cc1:CascadingDropDown>
<asp:DropDownList ID="ddlDepartment" runat="server"
SelectedValue='<%# Bind("Department") %>'>
</asp:DropDownList>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server"
ControlToValidate="ddlDepartment"
InitialValue="" ErrorMessage="Department is required"
Display="Dynamic" >*</asp:RequiredFieldValidator>
<asp:DropDownList ID="ddlEquipment" runat="server" SelectedValue='<%# Bind("Equipment") %>'>
</asp:DropDownList>
<asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server"
ControlToValidate="ddlEquipment"
InitialValue="" ErrorMessage="Department is required"
Display="Dynamic" >*</asp:RequiredFieldValidator>
That’s it! You now have cascading drop down lists that are fully functioning in a data bound formview.
I figured I would put together a simple tutorial since I’ve been getting a lot of traffic based on “iPhone Human Interface Guidelines.” This is probably due to one of my earlier blog post, “Developing My First iPhone App.” I failed to adhere to the guidelines in the beginning, so my app was originally rejected. Here is a simple tutorial so you don’t have the same issue as I did.
Download the Reachability project from Apple. The link to the project is:
http://developer.apple.com/iphone/library/samplecode/Reachability/index.html
The two files we will need are: Reachability.h and Reachability.m
Add SystemConiguration Framework:
1. Control click (right click) on the Frameworks folder and select Add then select Existing Frameworks.
2. Scroll down and select SystemConfiguration.framework.
3. Click Add.
4. Control click (right click) on the project icon and select Add then select Existing Files.
5. Find the Classes folder in the Reachability project, and select the files Reachability.h and Reachability.m.
6. Click Add, then make sure the check box is selected for “Copy items into destination group’s folder (if needed).”
7. Click Add.
Inside ViewController.h file, add the following statement to the top of the header file.
#import "Reachability.h"
Inside the interface definition of the view controller, add the variable definitions:
NSString *urlAddress;
NSURL *url;
NSURLRequest *requestObj;
NetworkStatus remoteHostStatus;
NetworkStatus internetConnectionStatus;
Add the following properties:
@property (nonatomic, retain) NSString *urlAddress;
@property (nonatomic, retain) NSURL *url;
@property (nonatomic, retain) NSURLRequest *requestObj;
@property NetworkStatus remoteHostStatus;
@property NetworkStatus internetConnectionStatus;
Inside ViewController.m file add the synthesize statements after the implementation statement:
@synthesize webView, urlAddress, url, requestObj;
@synthesize remoteHostStatus, internetConnectionStatus;
Inside the viewDidLoad method, add the following lines of code to set the variables:
[[Reachability sharedReachability] setAddress:@"http://www.apple.com"];
[[Reachability sharedReachability] setNetworkStatusNotificationsEnabled:YES];
Inside the programming logic, use the following lines of code to test network connectivity. Substitute the code you would like to execute where the “NSLog(@”Connection Made”)” statement is.
// Query the SystemConfiguration framework for the state of the device's network connections.
self.remoteHostStatus = [[Reachability sharedReachability] remoteHostStatus];
self.internetConnectionStatus = [[Reachability sharedReachability] internetConnectionStatus];
// Check if there is a connection
if (self.internetConnectionStatus == NotReachable && self.remoteHostStatus == NotReachable)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error Loading"
message:@"No Internet Connection"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
} else {
NSLog(@"Connection Made");
}
Don’t forget to clean up and add the following statements to the dealloc method.
[urlAddress release];
[url release];
[requestObj release];
Step 1: Download Cocos2d from the project website.
Step 2: Unzip the downloaded file in Step 1. If you are running Snow Leopard, it most likely will be in the downloads folder. Move the newly unzipped folder to the Desktop.
Step 3: Open Terminal and change the directory to the cocos2d folder on the desktop.
cd desktop/cocos2d-iphone-0.8.2
Step 4: Run the install template script.
./install_template.sh
The process is complete. Startup XCode and have fun!

Apple’s iTunes is a little lacking in the department of rating apps. Mostly when anyone rates an app they do so when they are deleting it from their iPhone, or if they really really love the app. Another thing that is lacking is allowing the developers to have a line of communication with the app users. I thought a survey might help bridge this gap and help me to communicate with the users of my app. I’ve had a survey online since July to collect some feedback from the users of my app.
Results:
Out of 62 people who have filled out the survey, PA Traffic Cams has an overall rating of 3.9 out of 5. Mostly everyone said they would recommend the app or already has recommended it. There were 4 people who said they wouldn’t.
Features:
Over half of the responders have said they loved the traffic speed map feature, and almost all of the rest have found it moderately to somewhat useful. I’m glad that it was a useful feature. Google has released a newer version of their maps. I’m waiting on them to implement this feature into the latest version of their maps. Since I am running the older version, it runs a little bit on the slow side.
One thing to note, I do not control how many cameras or in which location the cameras are placed. PennDOT is solely responsible for the cameras, and I am in no way shape or form associated with them. I merely have created an app to allow users to easily navigate and view them. I try my best to check PennDOT’s website and update the app with new cameras when they are made available. If you know a link to any cameras not on the app, please send me an email and I will work on adding them.
A few of you have requested making this app for the BlackBerry. I’m sure people on the Android will also want this app. I unfortunately do not own a BlackBerry or an Android which creates a little bit of a challenge for me. I can test the app in the simulators, but I have no way to know if it will actually work on the device. I don’t ever want to put out software that does not function. Things may change in the future, but for the moment I will not be developing for the other phones.
Thank You!
Thank you to everyone who has filled out the survey. I do appreciate the time everyone took to fill it out. Your feedback will allow me to determine what features to add in upcoming releases. Speaking of which… If you have an idea please send me an email, I would love to hear about it.


