Accelerometer in the iPhone Simulator
It can be a frustrating and time consuming task to work with the accelerometer feature in iPhone development. The iPhone Simulator does not come with any built-in capabilities to receive accelerometer events from factory.
Some developers accomplished a way to simulate it in the Simulator. One technique involves using a third party library that generate events and send them to your program. Another technique is kind of esoteric, as it reads your internal MacBook accelerometer and handle them as they would come from an iPhone. I just can’t imagine myself turning my MacBook upside-down just to test our game
I got a simple solution to simulate it. First I call the accelerometer from my update function (notice that I’m using a preprocessor macro), using nil as parameters:
#ifdef ACCELEROMETER_SIM [self accelerometer:nil didAccelerate:nil]; #endif
Then, on the accelerometer function, I test the program directly inputting the vectors that I need to test. In this case I want to test the Y axis:
- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration
{
// Use a basic low-pass filter to keep only the gravity component of each axis.
mAccelX = (acceleration.x * FILTER) + (mAccelX * (1.0 - FILTER));
mAccelZ = (acceleration.z * FILTER) + (mAccelZ * (1.0 - FILTER));
#ifdef ACCELEROMETER_SIM
mAccelY = (-1.0f * FILTER) + (mAccelY * (1.0 - FILTER));
#else
mAccelY = (acceleration.y * FILTER) + (mAccelY * (1.0 - FILTER));
#endif
}
It’s super simple, and you can have your tests right from your iPhone Simulator. No more uploading to device just to test
Dealing with NSCalendar and dates
If you need to work with dates on iPhoneOS, chances are you will need to use NSDate. Furthermore, if you need to work with timeframes, and also do some calculations for time differences, you should also know NSCalendar.
If you already saw the code below, you are right. Cashtown begins in 1958, that’s our creation time for the game. So day 1 in the game is Jan 1st, 1958. To set up this date, you should use a NSDateComponents, that only stores this value, look at line 33. It doesn’t mean anything, as a NSDateComponents must rely on some kind of calendar.
You can choose weird and crazy calendars, but for us, the Gregorian is good enough. As this function gives the default calendar to iPhoneOS, we are just getting the current calendar on line 31.
On line 38 we set mCreationDate (which is a NSDate) to the Component date, using a calendar. No problems, BUT there is a caveat here. You need to retain this value! First I thought that as this calendar comes from a NSCalendar class method (line 31) I would not need to retain. If you didn’t insert the retain keyword, you will find that mCreationDate is gone
Also, don’t forget to dealloc it on destruction, like we do on line 46.
@interface Sample : NSObject
{
NSDate* mCreationDate;
int mCreationDay;
int mCreationMonth;
int mCreationYear;
}
@property (retain) NSDate* mCreationDate;
@property (assign) int mCreationDay;
@property (assign) int mCreationMonth;
@property (assign) int mCreationYear;
@implementation Sample
@synthesize mCreationDate;
@synthesize mCreationDay;
@synthesize mCreationMonth;
@synthesize mCreationYear;
-(id)init
{
[super init];
if (self != nil)
{
mCreationDay = 1;
mCreationMonth = 1;
mCreationYear = 1958;
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setDay:mCreationDay];
[components setMonth:mCreationMonth];
[components setYear:mCreationYear];
mCreationDate = [[currentCalendar dateFromComponents:components] retain];
[components release];
}
return self;
}
- (void) dealloc
{
[mCreationDate release];
[super dealloc];
}
All the colors and art of a time
Defining the game concept was kind of easy. Developing it actually required research and a proper method. It was almost immediate the conception of its art: the 50s breathes images! No, they expire, outwards, on your face, colors, shapes, product design, music idols, non-music idols, smiling girls in painted posters and of course, milkshakes. If you’re from my generation, you can see this kind of thing all the time in a Back to the Future movie, the first one. Or in any other retro work. The 50’s, up to the 60’s before hippie movement, comes in a pastel color, like Jetsons and so on.
We needed an icon. The game concept shown that Cashtown itself was a simulated mechanical box, like a mechanical toy that a child could grab into their hands. The child would grow and would have it as an iPhone. One specific object became an symbol of that time: the Jukebox. Our Cashtown game resembles a jukebox. It has panels like clock radio displays that you would find at grandma’s house, but it’s still a jukebox. From product design to visual identity that simulates realism even to that time printing layout, it was a very enjoyable task to do.

Cashtown first coins using 50’s printing.
A bit of its way of thinking
To conceive Cashtown we had to think in a new and different way. This new way allowed us to explore what each technical limitations would mean. The game’s branding mix and the symbolism in its concept are spread like a bolt in each game aspect that was relevant to the gamer and also true to the rich symbolism that it just brings back.
Each game production area received proper attention like art, sound, commentaries, the cool elements of game design, all of which integrates to the concept and with each other. It was a nice to develop and still be developing Cashtown.
This energizes the entire production chain!
Our games are exclusive
Why?
- Original concept
- Pick-up-and-play experience
- Balance of challenge and ease of use (easy to learn, hard to master)
- Innovative and comprehensive gameplay
- Pleasant visual identity
- Unforgettable social experiences (depending on game context)
- Compelling uses of paid downloadable content (depending on game context)
- Original creative methodology
See also
- Aurore ·· The wisdom of a symbolic essence
- Train simulator for Vale ·· Distributed computing = DVDs
- Who we are ·· Daniel Mafra
- Contact ·· Email
- Contact ·· Address
- Train simulator for Vale ·· Phase one deliverable
- How we work ·· Experience
- Contact ·· Phone
- Our business ·· Indie
- Who we are ·· Marcelo Catach


