OpenGL vs iPhone CALayer
September 7, 2009
I wanted to talk about OpenGL layer and iPhone native UIKIT performance issue. Let’s talk about it. OpenGL is also CALayer and this is why you can add as sub view in a window. So, why not use multiple UIView instead of OpenGL for 2D game or sprite based game? Ya, we can do so but before doing this start your paper work and find out how many animating layer will be in your scene. All UI element take time from main run loop. In that case your context drawing and logic will be updated in same thread.
From game development point view you will create a NSTimer and will run in some FPS but mind it, it may not call on that duration if iPhone native drawing take too much time. Your equation will fail if you animate 5-8 animating view want consistent 60 FPS or like so. For 1/60.0 ms it may call 1/30.0 or 1/20.0 or multiple of it because iPhone refresh rate locked to 60.0 FPS.
In the other hand OpenGL is a single UI layer and less time in UI native drawing. So, you have all time to split logic and render. You may use Constant FPS and max game logic or Max FPS and constant game logic. As a game developer you should know that, game run loop is the heart of a game. You have to very careful in the circumstances. Device like iPhone you should create you game loop for Max FPS and constant game logic. It will give much better output.
NSURL
September 7, 2009
Use UTF8 encoding while creating NSRUL from NSString from following function
- (NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding
Otherwise NSURL will not be valid.
UIAlterView to take user Input
September 4, 2009
Sometimes we need to take user name. There are lot of way we can do this but I think people will like UIAlerview style most. Here is a code segment that can take user input by Alertview: [Adjust position and other parameter for your case]
UIAlertView *myAlertView = [[UIAlertView alloc]
initWithTitle: @”Enter Your Name”
message:@”Enter Name”
delegate:self
cancelButtonTitle:@”OK”
otherButtonTitles: nil];
myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 40.0, 260.0, 25.0)];
CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0.0, 80.0);
[myAlertView setTransform:myTransform];
myTextField.text = @”";
myTextField.delegate = self;
myTextField.textAlignment = UITextAlignmentCenter;
myTextField.backgroundColor = [UIColor whiteColor];
myTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
myTextField.keyboardType = UIKeyboardTypeAlphabet;
myTextField.keyboardAppearance = UIKeyboardAppearanceAlert;
myTextField.autocapitalizationType = UITextAutocapitalizationTypeWords;
myTextField.autocorrectionType = UITextAutocorrectionTypeNo;
[myAlertView addSubview:myTextField];
[myAlertView show];
[myAlertView release];
Final Touch!!!
September 4, 2009
Giving final touch on my 3 iPhone app. Most of them are game. I think people will like it. All of them are based on iPhone native UIKIt. In my opinion there is a marginal line between UIKIT based game and OpenGL game. Hope will explain it in some day. Mind it, you can do most of 2D game by native API, you don’t need OpenGL access. But some case you have to use it.