StickWars Version 1.1 Accepted and in App Store

Posted in StickWars on April 15th, 2009 by Eric – 11 Comments

At last! Wizards, Archers, difficulty levels, global high scores, and more!

Enjoy.

Welcome!

Posted in News on April 13th, 2009 by Eric – 20 Comments

Welcome to my site. I initially created it with the purpose of showcasing my development experience while creating my first iPhone game, StickWars. However, after the release and huge market response to the game, this site mainly serves to provide news and support for StickWars. You can find answers to many questions in my forums as well as post any other questions you might have.

While a lot of the posts are about updates about StickWars, I try to post code snippets and tips to get through roadblocks that I experienced while building my first iPhone game. If you have questions or would like to see some code to help you along, contact me and I’ll try to throw something up.

Integrating Chipmunk into Objective C iPhone Games

Posted in cocos2d iPhone, iPhone Development on April 13th, 2009 by Eric – 6 Comments

When working with Cocos 2d iPhone, a lot of the sample code provided that shows how to hook into the Chipmunk physics engine using static functions outside of any Objective C object. While this is the most straightforward way to get the engine up and running, it restricts what you can do later on.

Instead, you need to create a static function which takes two parameters, the object being updated and the objects container. Here’s some code:

This is the static function which goes outside your class implementation. Notice that we don’t actually do any of the object updates here. This is good, because we can’t access any of the internal state in the container in this method.

static void updateEachShapeCallback(void *ptr, void *parent)
{
	GameController *parentObject = (GameController *)parent;
	[parentObject updateShape: ptr];
}

Note that my container, called GameController, is a CocosNode so when were ready to start the game we can call

[self schedule: @selector(step:)];

to update the shapes.
This goes inside the implementation of your container.

- (void) step: (ccTime) delta
{
    int steps = 1;
    cpFloat dt = delta/(cpFloat)steps;
    for(int i=0; iactiveShapes, &updateEachShapeCallback, self);
    cpSpaceHashEach(space->staticShapes, &updateEachShapeCallback, self);
}

Add in the updateShape:(void *)ptr method to your GameController interface file and then implement as

- (void) updateShape:(void *)ptr {
	cpShape *shape = (cpShape*) ptr;
	Touchable *obj = shape->data;
 
	if(obj) {
		cpBody *body = shape->body;
		[obj setPosition: cpv( body->p.x, body->p.y)];
		[obj setRotation: (float) CC_RADIANS_TO_DEGREES( -body->a )];
 
		// do whatever else you want here! you have all the the state you should need!
		// just avoiding creating objects anywhere from here as that will slow your game down
	}
}

I adopted this solution from instructions I found at Using native Objective-C methods for C Callbacks.

Unofficial App Store Rejection Criteria

Posted in Distribution, iPhone Development on April 13th, 2009 by Eric – Be the first to comment

I found this post to be very informative, and possibly helped to prevent my App from being rejected the first round (I had enabled constant vibration while the player was under attack).

AdMob Ad to Landscape Orientation

Posted in cocos2d iPhone on April 13th, 2009 by Eric – 4 Comments

I checked around the net and found some people looking for this, but nobody who actually posted a code example. So here it is, code to make your Ad Mob ad shift to landscape orientation. My code makes it appear on the bottom, enlarged a little bit, with the device rotated to landscape counter-clockwise.

Add in a UIView called adContainer in your delegate interface declaration, and then update the standard Ad Mob methods as follows.

- (void)showAd 
{	
	adMobAd = [AdMobView requestAdWithDelegate:self]; // start a new ad request
	[adMobAd retain]; // this will be released when it loads (or fails to load)
	adContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 432, 320, 48)];
}
#define degreesToRadians(x) (M_PI * x / 180.0)
 
- (void)didReceiveAd:(AdMobView *)adView 
{
	[adContainer addSubview: adMobAd];
	[window addSubview:adContainer];
	CGAffineTransform makeLandscape = CGAffineTransformMakeRotation(degreesToRadians(90));
	makeLandscape = CGAffineTransformTranslate(makeLandscape, -480/2 + 48/2, 320/2 - 48/2 - 12);
	makeLandscape = CGAffineTransformScale(makeLandscape, 480.0/320, 480.0/320);
	adContainer.transform = makeLandscape;
	autoslider = [NSTimer scheduledTimerWithTimeInterval:AD_REFRESH_PERIOD target:self selector:@selector(refreshAd:) userInfo:nil repeats:YES];
}
- (void)removeAd 
{
	[adMobAd removeFromSuperview];
	[adMobAd release];
	adMobAd = nil;
 
	[adContainer removeFromSuperview];
	[adContainer release];
	adContainer = nil;
}

This was actually my first experience using the CG transforms, so please be gentle if there’s a better way :) .

iPhone App Ad Hoc Distribution Gotchas

Posted in Distribution, iPhone Development on April 13th, 2009 by Eric – 32 Comments

I spent more time trying to get Ad Hoc distribution work than any other issue that should have taken 15 minutes. There are a number of things which can go wrong, some of which are ridiculous and Apple will no doubt fix in time, but for now you should know these:

The biggest gotcha: you can not use the “Compress” option in Finder to bundle the Ad Hoc package. It adds files that cause iTunes to freak out. I wrote a quick shell script to bundle everything up and zip it together using the command line zip tool.

mkdir Payload
cp -rp MyApplication.app Payload/
zip -r MyApplication.ipa iTunesArtwork Payload

This way, you can give people the .ipa and .mobileprovision file. Tell them to drag the .mobileprovision into iTunes, and then double click the .ipa. How easy was that?

Another semi-obscure fact: iTunesArtWork is a 512×512 png, named simply ‘iTunesArtwork’ without the extension that needs to be included ONLY with Ad Hoc copies so the icon shows up in the iTunes window. You don’t need to include it, but if you do make sure you only do so when sending out Ad Hoc copies.

One more thing that caught me over and over again: don’t forget to increment the version number in your info.plist file before giving Ad Hoc users a new copy! iTunes is really sneaky about what happens here…in both cases it says the application is already installed, and asks if you want to replace it, but if you try to replace with the same or lower version number, it won’t actually do anything.


If you are getting

Application was not installed on the iPhone because it could not be verified.

then your profile isn’t valid and you should check out this post. This biggest thing to remember is

  1. Delete all the profiles stored in ~/Library/MobileDevice/Provisioning Profile.
  2. Double click your .mobileprovision file and it will get loaded into XCode.
  3. Quit XCode completely. I’m not sure why this is necessary, but often XCode refuses to build unless it starts up with the profile already ready.

Lastly, ensure not only that Entitlements.plist is included in your project (click File, New File, Code Signing, Entitlements), and that get-task-allow is unchecked, but in your “Ad Hoc” build profile (Project, Edit Active Target) expand the list to “All Settings” make sure the “Code Signing Entitlements” field is filled out with your “Entitlements.plist”.

StickWars – Siege renamed to StickWars

Posted in StickWars on April 12th, 2009 by Eric – 26 Comments

The new homepage for the game is located at http://johnehartzog.com/projects/stickwars/

StickWars – Siege ranked #19 worldwide in Paid Apps

Posted in StickWars on April 7th, 2009 by Eric – Be the first to comment

Before I took it down today, StickWars – Siege was ranked #19 in iTunes Paid Apps section, of all apps. Pretty cool! Hopefully the re-release will see the popularity increase even more :D .

StickWars – Siege on AppStore!

Posted in StickWars on April 1st, 2009 by Eric – Be the first to comment

Full Version: StickWars - Siege

Lite Version: StickWars - Siege Lite

StickWars – Siege Early Release Testing

Posted in StickWars on March 24th, 2009 by Eric – Be the first to comment

Please post any bugs at http://johnehartzog.com/forum/viewforum.php?f=4.

If you have any feature requests or suggestions, throw them up at http://johnehartzog.com/forum/viewforum.php?f=5.