Thursday, December 17, 2009

Enable and disable keyboard

1) go into interface builder and add a text field.
2) Add this code in your .h file:

Code:

-(IBAction) endText;

3) Add this code in your .m file:

Code:

- (IBAction) endText {

}

Wednesday, December 16, 2009

Global variable in Obj c

It is simple. In any .h file, write:
Code:

extern int variable;

Put this declaration *outside* of any Objective-C block like @interface...@end. You can place it before the @interface or after the @end. Either way is just fine.

Then, define the variable in any .m file (it doesn't matter which one, but only place it in one file):

Code:

int variable;

Tuesday, December 15, 2009

playing sound infinitie and then stop on click

in .h add
#import AudioToolbox/AudioServices.h
#import AVFoundation/AVFoundation.h


and declare
AVAudioPlayer *audioPlayer

in .m

inside 1st loaded ()

NSString *newAudioFile = [[NSBundle mainBundle] pathForResource:@"2000hz" ofType:@"wav"];

audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:newAudioFile] error:NULL];

[audioPlayer setDelegate:self];
[audioPlayer setNumberOfLoops:-1];
[audioPlayer prepareToPlay];
BOOL plays = [audioPlayer play];



and to stop sound
write this on view change


[audioPlayer stop];

Sunday, December 13, 2009

random Things under control

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
for(newBall in enemies)
{
newBall.center = CGPointMake(location.x,location.y);
}
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
for(newBall in enemies)
{
newBall.center = CGPointMake(location.x,location.y);
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
for(newBall in enemies)
{
newBall.center = CGPointMake(location.x,location.y);
}
}

////////////

sound code

NSString * path = [[NSBundle mainBundle] pathForResource:@"ballhitbar" ofType:@"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);


and to play wrte this

AudioServicesPlaySystemSound(soundID);

///////////////////////////////////// random
//Here is the spawnE...

-(void)spawnE {



enemies = [[NSMutableArray alloc] init];
UIImage *enemyImage = [UIImage imageNamed:@"enemy.png"];
UIImageView *newEnemy = [[UIImageView alloc] initWithImage: enemyImage];



int randomX = arc4random() % 320; // number from 0 to 319

newEnemy.center = CGPointMake( randomX, 0);


[enemies addObject:newEnemy];


[self addSubview: newEnemy];





}


///////// or
enemies = [[NSMutableArray alloc] init];

UIImage *enemyImage = [UIImage imageNamed:@"bug.png"];


for (int i=0; i<12; i++){
newEnemy = [[UIImageView alloc] initWithImage: enemyImage];



int randomX = arc4random() % 320; // number from 0 to 319
int randomY = arc4random() % 480;

newEnemy.center = CGPointMake( randomX,randomY);// working all over screen



[enemies addObject:newEnemy];


[self addSubview: newEnemy];

//newEnemy.userInteractionEnabled = YES;

}
//[self move];



}



//////////////

Thursday, December 3, 2009

function sytanx in obj c

in .h file
//
-(void)create;


/// in .m file

-(void) create
{
// write here
}



// call function
[self create]; // either in viewDidload() or anywer

FEEDJIT Live