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:


-(IBAction) endText;

3) Add this code in your .m file:


- (IBAction) endText {


Wednesday, December 16, 2009

Global variable in Obj c

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

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):


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)
{ = 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)
{ = 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)
{ = 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


///////////////////////////////////// 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 = 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; = 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

/// in .m file

-(void) create
// write here

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

Monday, October 26, 2009


for (i = 0; i < 50; i++) {
circleDef.radius = Math.random()/20+0.02;

bodyDef = new b2BodyDef();
bodyDef.allowSleep = true;
bodyDef.linearDamping = 0.1;
bodyDef.angularDamping = 0.1;

b = world.CreateBody(bodyDef);


var circle:Circle=new Circle()
circle.x= b.GetPosition().x* 50
circle.y= b.GetPosition().y* 50
circle.rotation = b.GetAngle() * (180/Math.PI);

b.m_userData = circle;

Thursday, September 24, 2009


Plus signs denote class methods, minus signs denote instance methods.
Class methods have no access to instance variables.
@implementation classname
+classMethod {
// implementation
-instanceMethod {
// implementation



Once an Objective-C class is written, it can be instantiated. This is done by first allocating the memory for a new object and then by initializing it. An object isn't fully functional until both steps have been completed. These steps are typically accomplished with a single line of code:

MyObject * o = [[MyObject alloc] init];

The alloc call allocates enough memory to hold all the instance variables for an object, and the init call can be overridden to set instance variables to specific values on creation. The init method is often written as follows:

-(id) init {
self = [super init];
if (self) {
ivar1 = value1;
ivar2 = value2;
return self;


Properties are implemented by way of the @synthesize keyword, which generates getter and setter methods according to the property declaration. Alternately, the @dynamic keyword can be used to indicate that accessor methods will be provided by other means.

Tuesday, September 22, 2009


In Cocos2d iPhone you'll be dealing with the Scene and Layer classes frequently. A Scene is what the players can see at a given time, and is composed of one or more Layers. To display a specific Scene, you tell the Director (which is a singleton) to play it.

Friday, September 18, 2009

kaminey Night


Any change to a view's position, scale, or rotation can now be stored in a property of the view called transform. It's a CGAffineTransform struct, and it's a bit cryptic if you've never worked with transformation matrices before.

A transformation matrix nothing more than a two-dimensional array of numbers. Okay, perhaps I shouldn't say "just", as transformation matrices are quite powerful. They can store complex changes to the position and shape of an object, including rotating, scaling, moving, and skewing (or shearing) the view as it's drawn. This adds a little bit of programmer complexity if you want to do anything more than the absolute basics, but it opens up a world of possibilities.

To translate a view from its current position, you would pass the view's transform property here. To translate the view from its original position, you would pass in CGAffineTransformIdentity. Here is an example that would move the view five points to the right and ten points down.

theView.transform = CGAffineTransformTranslate(theView.transform, 5.0, 10.0);

Monday, September 14, 2009

interface rotation based on hand movement

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

Tuesday, September 8, 2009

IPHone timer Event

objectmoveTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(objectTimer) userInfo:nil repeats:YES];


// THis is execute Continously // since repeat is set to Yes :)

Monday, September 7, 2009

running Apps

in the "target " go to properties and set identifier as "com.ihexcode.first"
and add .mobileprovision and Distribution to your project

Friday, September 4, 2009

Thursday, September 3, 2009

Defining a Class

Defining a Class

Much of object-oriented programming consists of writing the code for new objects—defining new classes. In Objective-C, classes are defined in two parts:


An interface that declares the methods and instance variables of the class and names its superclass

An implementation that actually defines the class (contains the code that implements its methods)

Although the compiler doesn’t require it, the interface and implementation are usually separated into two different files. The interface file must be made available to anyone who uses the class.

A single file can declare or implement more than one class. Nevertheless, it’s customary to have a separate interface file for each class, if not also a separate implementation file. Keeping class interfaces separate better reflects their status as independent entities.

Interface and implementation files typically are named after the class. The name of the implementation file has the .m extension, indicating that it contains Objective-C source code. The interface file can be assigned any other extension. Because it’s included in other source files, the name of the interface file usually has the .h extension typical of header files. For example, the Rectangle class would be declared in Rectangle.h and defined in Rectangle.m.

Separating an object’s interface from its implementation fits well with the design of object-oriented programs. An object is a self-contained entity that can be viewed from the outside almost as a “black box.” Once you’ve determined how an object interacts with other elements in your program—that is, once you’ve declared its interface—you can freely alter its implementation without affecting any other part of the application.

Class Interface

The declaration of a class interface begins with the compiler directive @interface and ends with the directive @end. (All Objective-C directives to the compiler begin with “@”.)

@interface ClassName : ItsSuperclass


instance variable declarations


method declarations


The first line of the declaration presents the new class name and links it to its superclass. The superclass defines the position of the new class in the inheritance hierarchy

If the colon and superclass name are omitted, the new class is declared as a root class, a rival to the NSObject class.


Class definitions are additive; each new class that you define is based on another class from which it inherits methods and instance variables. The new class simply adds to or modifies what it inherits. It doesn’t need to duplicate inherited code.

Inheritance links all classes together in a hierarchical tree with a single class at its root. When writing code that is based upon the Foundation framework, that root class is typically NSObject. Every class (except a root class) has a superclass one step nearer the root, and any class (including a root class) can be the superclass for any number of subclasses one step farther from the root. Figure 1-1 illustrates the hierarchy for a few of the classes used in the drawing program.

Some Drawing Program Classes

Friday, August 28, 2009

iphone video

skin example part 2

@ set widht, height and skin in diff class
- (id)init {
if(self = [super init]) {
[self setBodyDef:new b2BodyDef];
[self setShapeDef:new b2PolygonDef];
[self setSize:CGSizeMake(64.0f, 64.0f)];
[self setHighlightedView:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ObstacleHighlighted.png"]] autorelease]];/// skin code by default
[self setNormalView:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ObstacleNormal.png"]] autorelease]];// skin at collision
return self;

Obstacle *anObstacle = [[[Obstacle alloc] init] autorelease];
[anObstacle setPosition:CGPointMake(60.0f, 130.0f)];
[anObstacle setRotation:45.0f];
[self addActor:anObstacle];


self :- self is simply a hidden parameter on every method. Like any other parameter, it receives its value from the function invocation.

When you type the following:
MyClass *myObject = [[MyClass alloc] initWithString:@"someString"];

The compiler converts this into function calls that look like this:
class myClass = objc_getClass("MyClass");
SEL allocSelector = @selector(alloc);
MyClass *myObject1 = objc_msgSend(myClass, allocSelector);

SEL initSelector = @selector(initWithString:);
MyClass *myObject2 = objc_msgSend(myObject1, initSelector, @"someString");

A method needs to know what data to act upon. The self parameter tells the class the data to act upon and so is essential to object oriented programming.

This statement may seem a little strange, since you can easily implement a method without using the self parameter by name. The reality is that the compiler uses the self parameter to resolve any reference to an instance variable inside a method.

If you had a class defined like this:
@interface MyClass : NSObject
NSInteger value;
- (void)setValueToZero;

///then the method:

- (void)setValueToZero
value = 0;
is converted by the compiler into:

void setValueToZero(id self, SEL _cmd)
self->value = 0;

So self is essential for accessing any instance variables, even if you never literally type "self".

Thursday, August 6, 2009



Thursday, July 23, 2009

Generic Body


public function AddSpringBox(_x:Number,_y:Number,_halfwidth:Number,_halfheight:Number,ang:Number):void {
var bodyDef:b2BodyDef = new b2BodyDef();
var boxDef:b2PolygonDef = new b2PolygonDef();
boxDef.density = 0.0;
var body:b2Body = m_world.CreateBody(bodyDef);

red=new Red;
red.x=body.GetPosition().x* 30;
red.y=body.GetPosition().y* 30;
red.rotation = body.GetAngle() * (180/Math.PI);

body.m_userData = red;

Monday, July 20, 2009

ADD body to an existing one

var wallSd2l:b2PolygonDef = new b2PolygonDef();
var wallBd2l:b2BodyDef = new b2BodyDef();

var boxDef11:b2PolygonDef = new b2PolygonDef()
var wallB2l:b2Body;

wallSd2l.SetAsBox(.1, 2);
wallB2l = m_world.CreateBody(wallBd2l);


boxDef11.SetAsOrientedBox(2, 0.1, new b2Vec2(0, 0), 0);//w h x y angle

Friday, July 10, 2009

Fly Up AND Left

var forcex=Math.round(body.GetPosition().x-bodya.GetPosition().x);
var forcey=Math.round(body.GetPosition().y-bodya.GetPosition().y);

var nullX=Math.sqrt((forcex)*(forcex) + (forcey)*(forcey))

//if (Math.abs(forcey)==0)///fly horizontal
if (Math.abs(forcex)==0)///fly up
//if(body.GetPosition().x>5 && body.GetPosition().x<7 && body.GetPosition().y<9)

body.ApplyForce( new b2Vec2(-3, 0), body.GetWorldCenter());

Wednesday, July 8, 2009

Set Mass At run Time

To change the mass at run time just make desity=0 at the time of defining body
and in At run time Change its Mass

var massData = new b2MassData();
massData.mass = 1; = new b2Vec2(-1,1);
wallBd.SetMass(massData);//wallBd is a body

bodyDef1.isSleeping = true; is used to make body active whenever its hit by anyobject

Thursday, July 2, 2009

Searching elements in ARRAY

import flash.display.Sprite;

public class Main extends Sprite{
public function Main(){
var letters:Array = ["a", "b", "c", "d", "a", "b", "c", "d"];

var match:String = "b";

for (var i:int = 0; i < letters.length; i++) {
if (letters[i] == match) {
trace("Element with index " + i + " found to match " + match);

Thursday, June 25, 2009

MochiAds + Highscore API

1)get the game code-- put it nywer
2) make ur class as dynamic
3)upload game
4)go for leadership board and get the code for high score

Wednesday, June 24, 2009

Tiled Layer

var maze:b2Body;
var mazeArr:Array = [[1,1,1,1,1,1,1,1,1],[1,0,0,0,0,0,0,0,1],[1,1,1,1,1,1,1,0,1],[1,0,0,0,1,0,0,0,1],[1,0,1,0,1,0,1,1,1],[1,0,1,0,1,0,0,0,1],[1,0,1,1,1,1,1,0,1],[1,0,0,0,0,0,0,0,1],[1,1,1,1,1,1,1,1,1]];

// Add the Maze
var bodyDefk = new b2BodyDef();
bodyDefk.position.Set(6.5, 3.5);
maze = m_world.CreateBody(bodyDefk);

for (var j:int = 0; j < 3; j++)
for (var k:int = 0; k < 3; k++)
if (mazeArr[j][k] == 1)
var boxDefk = new b2PolygonDef();
boxDefk.SetAsOrientedBox(0.5, 0.5, new b2Vec2(-4 + k, -4 + j), 0);
boxDefk.density = 4;
boxDefk.friction = 1;
boxDefk.restitution = 0.1;


Tuesday, June 2, 2009

back to basics

body.ApplyForce(new b2Vec2(20,0), body.GetWorldCenter())

body ---->

var bodyDef:b2BodyDef = new b2BodyDef();
//bodyDef.isBullet = true;/// penetrate object
var boxDef:b2PolygonDef = new b2PolygonDef();
boxDef.density = 1.0;
// Override the default friction.
boxDef.friction = 0.1;
boxDef.restitution = .4;
bodyDef.angle = 45//Math.random() * Math.PI;
body = m_world.CreateBody(bodyDef);
shape1=body.CreateShape(boxDef);//collsion wer shape1:*


wheel.x=body.GetPosition().x* 30;
wheel.y=body.GetPosition().y* 30
wheel.rotation = body.GetAngle() * (180/Math.PI);


Monday, May 11, 2009

make a object stop after sometime

if (bullet.GetLinearVelocity().Length() < 0.001){
stoppedForFrames += 1;
stoppedForFrames = 0;
if (stoppedForFrames >= 15){

Thursday, May 7, 2009

level lock code in AS3

write this code in 1st frame
var unLock:*;

var my_so:SharedObject = SharedObject.getLocal("store4");

if (my_so.size == 0) {

unLock = Level

} else {


make movieclips (to show all levels)
L1.buttonMode = true;//// its open

function LevelPlay(e:Event) {


L2.addEventListener(MouseEvent.CLICK,LevelPlay1);///its closed

function LevelPlay1(e:Event) {




/// this is the code for making button visible and non visible
for( var i=1;i<=unLock;i++)



finaly in UPdate fucntion() pass the data and store it like this



its done :)

Monday, May 4, 2009

rafter game

If you want to run swf in blogspot
here is the code


Sunday, May 3, 2009

fan effect code done

i was thinking of making something with Fan
so i did 1 module as how can one make object to sustain in AIR. :)
well the concept behind this is just make one Base object and one target Object
then find this distance between them and applyforce in y direction

like this
var forcex=Math.round(body.GetPosition().x-wallB.GetPosition().x);
var forcey=Math.round(body.GetPosition().y-wallB.GetPosition().y);

if (Math.abs(forcex)>=1&&Math.abs(forcey)>=1) {
body.ApplyForce( new b2Vec2(10/forcex, 50/forcey), body.GetWorldCenter());

Saturday, April 11, 2009

Game Story

My name is rahul singh i am working as Game developer
i would like to share my experience about Gaming
Recently i did one Game called Rafter and this game got selected by Big Fish Games
so now i am quite excited about my future Games .

Tuesday, February 3, 2009

Friday, January 23, 2009

Friday, January 9, 2009