Thursday, August 18, 2011

Following AppsAmuck's 31 Example Applications

Saw this site called AppsAmuck which provides 31 example applications. Just started yesterday and up to the 2nd one now. It's quite interesting as the site provides detail information plus the source code - although it's a bit out of date.

The 1st example is about showing a clock counting down to midnight. As shown below, the code can't compile in XCode 4, after some research on the net I got it working and added another clock on top - one showing the current time, the other showing the count down. I think this would be quite handy if you need to write some game and have a count down displayed somewhere.

The 2nd one is about animation. As the old code still compiles, I was a bit lazy and just played around with it, added another animation I downloaded somewhere (I forgot :-P ) about street fighter. Quite interesting watching it punching left, right and center above the lively fire background.

Wonder how many days can I go on, I think everyone should have a try!

Wednesday, August 17, 2011

List out all font names

Thanks to Ajnaware’s Weblog I was able to list out all the font names, as shown in the attached screen dump. You should have a try too!

[Update] Please see this new post which shows improved version that also displays each font in scrollable view.



    // List all fonts on iPhone
    NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
    NSArray *fontNames;
    NSInteger indFamily, indFont;
    for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
    {
        NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
        fontNames = [[NSArray alloc] initWithArray:
                     [UIFont fontNamesForFamilyName:
                      [familyNames objectAtIndex:indFamily]]];
        for (indFont=0; indFont<[fontNames count]; ++indFont)
        {
            NSLog(@"    Font name: %@", [fontNames objectAtIndex:indFont]);
        }
        [fontNames release];
    }
    [familyNames release];


[Update 05/04/2012] Found this web site which listed out all iOS fonts for iOS5, which you might also find it handy.

Sunday, August 14, 2011

Open Source Game: Simple Ball Bouncing Game Ver 2

I expanded the simple ball bouncing game a bit. It now has a few more functions:
-added game pause function
-added left/right direction movement, toggle between up/left-right movement with direction button
-starts with 1 ball, get extra ball every 100 points (max 5 balls)
-added device rotation handling
-added top score recording using application preference

A simple video of the game is below:


Also learned some new skills, this is my first project with proper device rotation handling (using empty NIB design as the NIB-less design still have problem with rotation handling), and also my first project with saving data in application preference.

For example: I was following the instructions from chapter 7 of "Beginning iOS 4 application Development" for device rotation handling. But found that if I use "willAnimateSecondHalfOfRotationFromInterfaceOrientation" I keep getting this strange message shown below and the program will stop after running for a while: "Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations."

Don't know what the hell is "two-stage rotation animation", but after a few searches on the net, I fixed it by replacing the "willAnimateSecondHalfOfRotationFromInterfaceOrientation" function with "willAnimateRotationToInterfaceOrientation".

The source code available here

Thursday, August 11, 2011

Open Source Game: Simple Ball Bouncing Game

Based on YouTube video http://www.youtube.com/watch?v=iGwZoowB-6Y&feature=related by TheEagle1100, I learned quite a lot of new things and created this new simple ball bouncing game: the timer, the game state, the way to move the balls, move the platform down, setup the scores, ...etc.

As shown in screen dump below, there's a few balls bouncing up and down, getting scores on every bounce. When the balls bounced above top 1/4 of the screen, the green platforms moved down and more new ones appeared at the top.

Due to the problem with the NIB-less template I used before - which wouldn't rotate properly, I now use an "empty" NIB, finally it rotates as expected this time.

Instead of 1 single ball and 5 hard coded IBOutlet in the YouTube video, in my project both the platforms and balls are defined using arrays, and you can freely adjust the parameters to get more platforms or/and balls. The NIB was left empty and all UIImageView, UIButton, UILabel objects were added by code.

In the YouTube video (not this one but part 8 or 9? can't remember), TheEagle1100 also demonstrated how to setup the code to control the ball movement in the real device by tilting it around. Unfortunately I only have the simulator, so that part wasn't included.

I also removed the menu and changed the ending part with a button. Hope you find it interesting.


Source to double simple game

Wednesday, August 10, 2011

When can we have XCode Running on iPhone/iPad?

Was thinking, now that the iPhone/iPad devices are getting more powerful in every generation, wonder how long will it take before Apple release a "portable/mobile" version of XCode that runs on iPhone/iPad? In that case, we can all do development on the same device, how cool is that?

Saturday, August 6, 2011

Can't have array in @property?

Was following this You Tube Video "Making a simple iPhone game, part 2 by TheEagle1100 (DBaird Software), but I tried to do it in slightly different way. Instead of declaring 5 UIImageView calling them "*platform1" to "*platform5", I used an array to save the effort of duplicating.

However when I put in declaration for @property as below, as shown in screen dump above I get 2 errors. 1st about "Property cannot have array or function type 'UIImageView *[5]", the 2nd one says "Property with 'retain' attribute must be of object type.

@property (nonatomic, retain) IBOutlet UIImageView *platform[5];

If I remove the "retain" it will get rid of the 2nd error, but the first error remains....

Based on my "limited" understanding of how "@property" works, it's mainly for the getter and setters, so may be I have to write my own getter/setter or try some other way...

Friday, August 5, 2011

Why my NIB-less projects won't auto-rotate?

Found a problem with the NIB-less projects I have created so far. For some unknown reason, it won't auto-rotate? That is, if I create a simple NIB-less project with only 1 button and 1 label, and then rotate the simulator to either direction, then even if I change the "shouldAutorotateToInterfaceOrientation" as below to always return "YES", it won't move at all?


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    //return (interfaceOrientation == UIInterfaceOrientationPortrait);
    return YES;
}


However, if I create another new project with NIB and create same button, label and same change to "shouldAutorotateToInterfaceOrientation" as above, both the button and label rotates nicely, why???

Very strange... Tried using the "nib2objc" tool to analysis the XIB file and it dumps lots of info about the view shown below, but still couldn't work out which property/attribute should be copied over to NIB-less version to make it auto-rotate... I am stuck :-( !!!


UIView *view6 = [[UIView alloc] initWithFrame:CGRectMake(0.0, 20.0, 320.0, 460.0)];
view6.frame = CGRectMake(0.0, 20.0, 320.0, 460.0);
view6.alpha = 1.000;
view6.alphaValue = // unknown property: 1;
view6.autoresizesSubviews = YES;
view6.autoresizesSubviewsForDevice = // unknown property: 1;
view6.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
view6.backgroundColor = [UIColor colorWithWhite:0.750 alpha:1.000];
view6.backgroundFilters = // unknown property: (
);
view6.canDrawConcurrently = // unknown property: 0;
view6.clearsContextBeforeDrawing = NO;
view6.clipsSubviews = // unknown property: 0;
view6.clipsToBounds = NO;
view6.contentFilters = // unknown property: (
);
view6.contentMode = UIViewContentModeScaleToFill;
view6.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}");
view6.focusRingType = // unknown property: 0;
view6.frameCenterRotation = // unknown property: 0;
view6.frameOrigin = // unknown property: {0, 20};
view6.frameSize = // unknown property: {320, 460};
view6.hidden = NO;
view6.ibExternalIdentityShowNotesWithSelection = // unknown property: 0;
view6.multipleTouchEnabled = NO;
view6.opaque = YES;
view6.opaqueForDevice = // unknown property: 1;
view6.simulatedOrientationMetrics = // unknown property: [This value is not printable by ibtool (IBUISimulatedOrientationMetrics)];
view6.simulatedStatusBarMetrics = // unknown property: [This value is not printable by ibtool (IBUISimulatedStatusBarMetrics)];
view6.tag = 0;
view6.userInteractionEnabled = YES;
view6.wantsLayer = // unknown property: 0;