Tiled has a beautiful object layer where you can put characters, treasure chests, warp points to other levels and whatever else you can imagine. You just create an object layer then click on the object layer to create an object. Give it a distinct type so you can instantiate the object in your code.
For example, in my first level, I have a “player” object and a “skeleton” object. Here’s some of the code that instantiates the characters:
// explore object layer
NSMutableArray* ra = [objects objects];
for(i = 0; i < [ra count]; i++)
{
// get this object
CCTMXObject* o = [ra objectAtIndex:i];
// the tmx map will instantiate objects of known classes
// in trying this out it was too tricky and less control
// so we only mess with objects of type CCTMXObject
if([o class] == NSClassFromString(@"CCTMXObject"))
{
// loop over the object's properties
NSMutableDictionary* props = [o properties];
id type = [props valueForKey:@"type"];
// setup the player
if([type isEqualToString:@"player"])
{
Player* player = [[[Player alloc] init] autorelease];
player.position = [self propsXYToPoint:props];
[self addChild:player z:1 tag:kTagPlayer];
}
// setup a skeleton
if([type isEqualToString:@"skeleton"])
{
Skeleton* skeleton = [[Skeleton alloc] init];
skeleton.position = [self propsXYToPoint:props];
[self addChild:skeleton];
}
}
}
I spent most of day 7 researching Cocos2D iPhone’s sprites, sprite caches, animations and atlases. The thorn in my mind was trying to figure out a way to erase the ugly “transparent” brown color from the bitmaps using purely code. I was searching in earnest for this way because I don’t want to have to update thousands of bitmaps and erase ugly brown colors.
At the end of the day I gave up and just decided to pack the textures with Zwoptex and then remove the ugly brown color in Photoshop after it packed a nice PNG for me. Before Zwoptex would accept the bitmaps I had to convert them to PNG first. After an hour of frustratingly trying to do this with the horribly stupid Automator, I found the following command line utility which worked like a charm:
sips -s format png *.bmp --out pngs
I also had a bit of fun re-learning how circles work. Yay. Trigonometry is fun. Woooo. Here’s how the joystick button position is converted into player movement:
And the joystick button position is “clamped” to the edge of the joypad with the following code. Don’t ask me why we have to subtract half a PI for x and add half a PI for y… It just works that way.
Ahh! To exit the world of freeways, cops, registration, road rage, repairs, rush hour, tires, maintenance, driving, smog, and gas: what a relief!
Thinking back on all the times in my life without a car, I realize they have truly been the best, most memorable, most fun, challenging, physically rewarding times of my life! Growing up I walked to school and have the fondest memories. I traveled the world without a car for a year and it was beyond blissful. I lived in my home town with just a bicycle recently and completely loved it.
Day 5. 0:15. He floats as graceful as Tinkerbell in the night.
Conan. He doesn’t cry. He doesn’t even walk. He just floats everywhere but on top of rocks. Here’s a little bit of the code to implement the joystick-style movement pad:
Day 2 of Writing a Book About Writing an iPhone Game
0:47. A little barbarian moves across the screen when I click in the corners. Though he floats over rocks and that’s just not natural.
Day 3 of Writing a Book About Writing an iPhone Game
0:50. Conan gets frisky on the rocks… Still not crying.
Guess this book ain’t just gonna write itself, so I took one heavy first step and got a tiled background to load on the iPhone simulator using cocos2d’s TMXTiledMap class and a sweet map editor program called Tiled.
Here’s a bit of the code to load the tilemap file and move the map to the center of the screen:
2009 was the funk. Not “the funk” as in George Clinton, but the funk as in a gunky soul. 2010 couldn’t have come at a better time. It’s a new decade! Time to break out of the shell. Time to bust all the old barriers. Time to be happy. Time to completely let go. Time to stop living in the past. Time to stop staying in. Time to go out! Time to live. Time to thrive!
Thanks to Ron for the mentorship. Thanks to Beaver for the support. Thanks to Rachel for taking me camping. Thanks to Colin for always reminding me of what it is to live.
So easy to resolve to thrive. So difficult to go from funked to flowing. It’s all a trick of the curve of time. We’re either trending up or trending down. What seems like a plateau is just the the outer edge of the parabola, the “curve” of the earth to us ants.
So the first days of my resolve to thrive were sputtered. One minute I was up. The next minute I was down and all seemed unreachable, hopeless. For the first time I looked up the definition of despair in the dictionary.
Then, drop by drop, the water came back into my soul. And for both our benefits, here are the grams that finally tipped the scale:
Got a pair of suspenders (wow, I do have an ass)
Listened to Jeff Olson’s “The Slight Edge” on audio CD (thanks Glen)
Started writing a book about iPhone game programming (to generate cashflow and forget to worry about money)
Got fresh sheets, blankets and an awesome memory-foam mattress for my berth
Started to eat new foods
Stopped writing lists (just began doing what truly felt most important)
Tore off the door to my v-berth (doors are not meant for boats)
Began lifting weights again (gained 3 pounds already)
Started a habit of getting off the boat each morning (used to spend all day in the cave)
Went out dancing (and finally learned a few breakdancing basics)
Sold a lot of unnecessary equipment
Got a new pair of boots (and was given my first pair of Vans — thanks again Colin)
Found creative ways to reduce my expenses
Tossed the seats out of my dinghy (standing up is way more fun)
Put my car up for sale (was really hard to let go of my mental dependency on this luxury)
Started to look at fixed-gear bicycles (planning to purchase next week)
Cut a hole in my roof for a hatch (no more having to hunchback on the steps to the back deck)
Cut away half the kitchen to make room for a drum set
Got drums and put them on the boat!!!!!!! (lifelong dream)
Began to focus on getting to know new people
Started holding auditions for a drummer for Bullets in a Burning Box
Finally put my “couch” up for surf on couchsurfing.org (have always wanted to give back to the travel community)
Started standing straighter (my left shoulder used to scrunch from playing guitar so much)
Started to remember people’s names again
Got a new water filter cartridge
Drank up all the caffeinated tea on the boat (now using my urge for a kick to get ashore more)
Finally went in for an eye exam to get hard contacts (softies never worked for my astigmatism)
Remembered that I have an album to finish!!
I’ve noticed a couple things about myself that I really, really like:
I’ve gone to bed and even let whole days go by without smoking any weed.
I’ve noticed that I am befriending people for no particular reason, and enjoying my existing friendships more than ever.
In other words, my funky habits are dissolving and new, strong, good habits are forming.
Hope this blog entry inspires you! Start to make your dreams come true right now!!!!