Saturday, January 19, 2013

[iOS] Save Data into SQLite

Save the input data into SQLite.


[iOS] Find data from SQLite.

Find data from SQLite.

[iOS] Create SQLite table

Create SQL table with site name, user name, and password field to save it.

Thursday, January 17, 2013

[Android] slideshow on the main page.




Slideshow on main page. Add all of images into drawable folder. and

int imgid[]={R.drawable.s1,R.drawable.s2,R.drawable.s3,R.drawable.s4};

Make array like this, and copy below code into your activity.

[iOS] Calculation of the discount.

-(void) calculation
{
    
    float priceField = [PriceDecimal.text floatValue];
    float taxField = [RateDecimal.text floatValue];
    float discField = [DiscDecimal.text floatValue];
    
    if([usingTax isOn])
    {
        
        if([dallarOrPercent selectedSegmentIndex] == 0)
        {
            float price = (priceField * (1 - discField* 0.01 )) * (taxField*0.01+1);
            finalValueLabel.text = [NSString stringWithFormat:@"%.2f", price];
            float discValue = priceField * (discField *0.01)+ ((priceField * (discField *0.01))*(taxField*0.01));
            DiscLabel.text = [NSString stringWithFormat:@"%.2f", discValue];
        }
        else
        {
            float price = (priceField -  discField) * (taxField*0.01+1);
            finalValueLabel.text = [NSString stringWithFormat:@"%.2f", price];
            float discValue = discField *(1+taxField*0.01);
            DiscLabel.text = [NSString stringWithFormat:@"%.2f", discValue];
        }
    }
    else
    {
        if([dallarOrPercent selectedSegmentIndex] == 0)
        {
            float price = (priceField * (1 - discField* 0.01));
            finalValueLabel.text = [NSString stringWithFormat:@"%.2f", price];
            float discValue = priceField * (discField *0.01);
            DiscLabel.text = [NSString stringWithFormat:@"%.2f", discValue];
        }
        else
        {
            float price = priceField - discField;
            finalValueLabel.text = [NSString stringWithFormat:@"%.2f", price];
            float discValue = discField;
            DiscLabel.text = [NSString stringWithFormat:@"%.2f", discValue];
        }
    }
}

[iOS] Tighten Letter Spacing



Avoiding number is overflow the size of the label, we need to check mark on Tighten Letter Spacing.



Monday, December 31, 2012

[iOS] Jumping into iphone game development

If your character image is too big to catch a collision, you may need to make hidden rectangle for the jump action. When the jump action is called, it will move both of the actual image and collisionRect frame. Collision method only check the collision between hws and collisionRect.




- (void) fall
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.8];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animateRunning)];
    characterImage.frame = CGRectMake(characterImage.frame.origin.x, 90 +30, 175, 181);
    collisionRect.frame = CGRectMake(collisionRect.frame.origin.x, 90 +90, 26, 111);
    [UIView commitAnimations];
}

- (IBAction) jump
{
    [characterImage setAnimationImages:jumpAni];
    [characterImage setAnimationDuration:1];
    [characterImage setAnimationRepeatCount:1];
    [characterImage startAnimating];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(fall)];
    collisionRect.frame = CGRectMake(collisionRect.frame.origin.x, 90 -90, 26, 111);
    
    characterImage.frame = CGRectMake(characterImage.frame.origin.x, 90 -30, 175, 181);
    [UIView commitAnimations];
    [characterImage startAnimating];

}

[iOS] AVAudioPlayer delay first play

If your application's effect sounds is played a little late than actual action, you may need to load the sound file on the viewDidLoad for prepare to play.

Example code is below.

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setupArray];
    [self imgAlloc];
    courseNameField.text = courseName;
    
    NSString *backgroundSoundpath = [NSString stringWithFormat:@"%@%@", [[NSBundle mainBundle] resourcePath], @"/ahhh.mp3"];
    NSError *err00;
    ahhhPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: [NSURL fileURLWithPath:backgroundSoundpath] error:&err00];
    ahhhPlayer.currentTime = 0;
    [ahhhPlayer prepareToPlay];
    
    NSString *whoopiepath = [NSString stringWithFormat:@"%@%@", [[NSBundle mainBundle] resourcePath], @"/whoopie.wav"];
    NSError *err01;
    whoopiePlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: [NSURL fileURLWithPath:whoopiepath] error:&err01];
    whoopiePlayer.currentTime = 0;
    [whoopiePlayer prepareToPlay];
    
    NSString *jumppath = [NSString stringWithFormat:@"%@%@", [[NSBundle mainBundle] resourcePath], @"/WhoopFlp.wav"];
    NSError *err02;
    jumpPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: [NSURL fileURLWithPath:jumppath] error:&err02];
    jumpPlayer.currentTime = 0;
    
    gameTimer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(gameUpdate) userInfo:nil repeats:YES];
    
    [self animateRunning];
    [self backgroundSound];
    
}

Saturday, December 29, 2012

[iOS] Before Flipside View get input value from pop-up pane

Before game start, UIAlertView will pop-up to get course name, then pass the value to next page for display and start game on Flipside view.

- (IBAction)showInfo:(id)sender
{
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Welcome!!" message:@"Enter your course name:"
                                                    delegate:self cancelButtonTitle:@"Continue" otherButtonTitles:nil];
    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    UITextField * alertTextField = [alert textFieldAtIndex:0];
    alertTextField.keyboardType = UIKeyboardTypeDefault;
    alertTextField.placeholder = @"Enter your course name";
    [alert show];
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSString *buttonTitle=[alertView buttonTitleAtIndex:buttonIndex];
    if ([buttonTitle isEqualToString:@"Continue"]) {
        UITextField *textField = [alertView textFieldAtIndex:0];
        FlipsideViewController *controller = [[FlipsideViewController alloc]
                                              initWithNibName:@"FlipsideViewController" bundle:nil];
        controller.delegate = self;
        controller.courseName = textField.text;
        controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [self presentViewController:controller animated:YES completion:nil];
    }
}


Friday, December 21, 2012

[iOS] Jump Motion

In the CollegeSurvior, there are 5 motion captures in the jumping action. The swipe gesture recognizer will call the method to change the action images from running image array to jumping image array.