Ray Wenderlich Forums

Back in October I have the privilege to attend the Voices that Matter conference in Philadelphia. There I had the opportunity to meet a lot people in the iOS community to include Ray Wenderlich. Ray posts a ton of tutorials on his site and really gives back to the community. Recently he started looking for forum moderators, so I decided to send him an email to volunteer. Since I am one of the technical reviewers for the upcoming Cocos2D book, we thought it would be a great fit. I am excited to help out Ray, but more importantly give something back to the iOS community.

Go check out the forums at: http://www.raywenderlich.com/forums/



The new game Gopher Hunter for the iPhone/iPod Touch is now available in iTunes. This is my first game, and has been a great experience putting it together. Check it out!

Game Description:
Gophers have overtaken a farmer’s field, help keep these gophers under control by shooting them. Gopher Hunter is a mix of a shooting and whack-a-mole style game. Three game modes allow for a fun time, and Game Center achievements will keep you coming back for more.

Gopher Hunter now available in iTunes



A lot of people put great thought into what they would like to accomplish during the upcoming new year. I have used this blog as a way to share information that I think would be useful for iOS or ASP.NET developmers. I have sorted through keyword searches that linked to my site in an effort to better figure out which topics people want to read about. Here is the list of keywords:

  • cocosdenshion
  • cocos2d tutorial
  • cocos2d getting started
  • cocos2d tutorial level
  • cocos2d mario (I guess people really want to play this!)
  • cocos2d multi alert
  • cocos2d check network
  • hide tab bar ios
  • custom uitabbar selected item
  • iphone dev net reachability class
  • iphone nsurlrequest server reachable test
  • iphone remotehoststatus

Over the next year I will try to post as many tutorials as I can on topics such as network connectivity testing (updated code), tabbar customization, Cocos2D, and CocosDenshion. If anyone has other topics they would like to see covered, please post your request in the comments section below.



I recently came across a situation where it was useful to have a UITabBar based application, however the actual tab bar was an unnecessary item on the screen. This post is a mini tutorial on how to make this happen.

UPDATE: A few people have asked for the source code, so here is the project.

Inside “application:didFinishLaunchingWithOptions:” method:

tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:navController1, viewController1, viewController2, nil];
[window addSubview:tabBarController.view];
[self makeTabBarHidden:TRUE];

Here is the “makeTabBarHidden” method:

-(void)makeTabBarHidden:(BOOL)hide {
	// Custom code to hide TabBar
	if ( [tabBarController.view.subviews count] < 2 ) {
		return;
	}
 
	UIView *contentView;
 
	if ( [[tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] ) {
		contentView = [tabBarController.view.subviews objectAtIndex:1];
	} else {
		contentView = [tabBarController.view.subviews objectAtIndex:0];
	}
 
	if (hide) {
		contentView.frame = tabBarController.view.bounds;
	}
	else {
		contentView.frame = CGRectMake(tabBarController.view.bounds.origin.x,
		     tabBarController.view.bounds.origin.y,
		     tabBarController.view.bounds.size.width,
		     tabBarController.view.bounds.size.height - tabBarController.tabBar.frame.size.height);
	}
 
	tabBarController.tabBar.hidden = hide;
}

And you are probably wondering how to change the views that are normally controlled by the tab bar? Here is the answer…just simply change the selectedIndex property of the tab bar.

tabBarController.selectedIndex = 1;

The complete source code for the project.

Part of this code came from a post I found on iPhoneDevSDK.com, so I took it one step further and made it a complete solution.



Some pictures from the iPhone 4 release event in Shadyside, PA.


iPhone 4 End of line at Shadyside
iPhone 4 About to go in to the Apple Store



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:

1
2
3
#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.

1
2
3
4
5
6
7
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:

1
2
3
4
5
6
7
8
9
10
11
// 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.

http://itunes.com/apps/dctrafficcams



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).

Mario Level Cocos2d example

Do you have a good website or tutorial? Please let me know.