Wednesday, May 5, 2010
Back to basics
# @implementation shows a new keyword: super
* Similar to Java, Objective-C only has one parent class.
* Accessing it's super constructor is done through [super init] and this is required for proper inheritance.
* This returns an instance which you assign to another new keyword, self. Self is similar to this in Java and C++.
# if ( self ) is the same as if ( self != nil ) to make sure that the super constructor successfully returned a new object. nil is Objective-C's form of NULL from C/C++. This is gotten from including NSObject.
# After you've initialized the varialbes, you return yourself with return self;
# The deafult constructor is -(id) init;
# Constructors in Objective-C are technically just "init" methods, they aren't a special construct like they are in C++ and Java.
+ is used. The + denotes a class level function.
http://www.otierney.net/objective-c.html#downloading
http://www.atomicobject.com/pages/The+Objective+C+Language
Interface is a class which contain all unimplemented methods( can call them also abstract methods)
We will implement these methods in derived class of interface.
ie an interface is actually not inherited but implemented.
We cann't create an instance of interface object instead we can create an instance for derived class objects
//////////////////
classes in Objective-C provide the basic construct for encapsulating some data with the actions that operate on that data. An object is a runtime instance of a class,
Protocols and Delegates
Protocols and Delegates
A protocol declares methods that can be implemented by any class. Protocols are not classes themselves. They simply define an interface that other objects are responsible for implementing. When you implement the methods of a protocol in one of your classes, your class is said to conform to that protocol.
Protocols are used frequently to specify the interface for delegate objects. A delegate object is an object that acts on behalf of, or in coordination with, another object. The best way to look at the interplay between protocols, delegates, and other objects is to look at an example.
The UIApplication class implements the required behavior of an application. Instead of forcing you to subclass UIApplication to receive simple notifications about the current state of the application, the UIApplication class delivers those notifications by calling specific methods of its assigned delegate object. An object that implements the methods of the UIApplicationDelegate protocol can receive those notifications and provide an appropriate response.
The declaration of a protocol looks similar to that of a class interface, with the exceptions that protocols do not have a parent class and they do not define instance variables. The following example shows a simple protocol declaration with one method:
@protocol MyProtocol |
- (void)myProtocolMethod; |
@end |
Thursday, April 22, 2010
In the MVC design pattern, the model layer consists of objects that represent the data your application manages. The objects in this layer should be organized in the way that makes the most sense for the data. External interactions with model objects occur through a well-defined set of interfaces, whose job is to ensure the integrity of the underlying data at all times.
The view layer defines the presentation format and appearance of the application. This layer consists of your application’s windows, views, and controls. The views can be standard system views or custom views you create. You configure these views to display the data from your model objects in an appropriate way. In addition, your view objects need to generate notifications in response to events and user interactions with that data.
The controller layer acts as the bridge between the model and view layers. It receives the notifications generated by the view layer and uses them to make the corresponding changes in the data model. Similarly, if the data in the data layer changes for other reasons (perhaps because of some internal computation loop), it notifies an appropriate controller object, which then updates the views.
EXP--
View is just a GUI so when user interact with GUI (controller) and modify data indirectly(which is a model)
MVC
In the MVC design pattern, the model layer consists of objects that represent the data your application manages. The objects in this layer should be organized in the way that makes the most sense for the data. External interactions with model objects occur through a well-defined set of interfaces, whose job is to ensure the integrity of the underlying data at all times.
The view layer defines the presentation format and appearance of the application. This layer consists of your application’s windows, views, and controls. The views can be standard system views or custom views you create. You configure these views to display the data from your model objects in an appropriate way. In addition, your view objects need to generate notifications in response to events and user interactions with that data.
The controller layer acts as the bridge between the model and view layers. It receives the notifications generated by the view layer and uses them to make the corresponding changes in the data model. Similarly, if the data in the data layer changes for other reasons (perhaps because of some internal computation loop), it notifies an appropriate controller object, which then updates the views.
Wednesday, April 21, 2010
Revolute joint
var bodyDef2:b2BodyDef;
var boxDef2:b2PolygonDef;
bodyDef2 = new b2BodyDef();
bodyDef2.position.Set(26, 12.5);
//bodyDef2.angle = -.5;
boxDef2 = new b2PolygonDef();
boxDef2.SetAsBox(3, .1);//7
boxDef2.friction = .1;
boxDef2.density = 12.1;
/*
*/
body2 = m_world.CreateBody(bodyDef2);
body2.CreateShape(boxDef2);
body2.SetMassFromShapes();
/////////////// body 20
var bodyDef20:b2BodyDef;
var boxDef20:b2PolygonDef;
bodyDef20 = new b2BodyDef();
bodyDef20.position.Set(23, 12.5);
//bodyDef2.angle = -.5;
boxDef20 = new b2PolygonDef();
boxDef20.SetAsBox(.5, .1);//7
boxDef20.friction = .1;
boxDef20.density = 0;
/*
*/
body20 = m_world.CreateBody(bodyDef20);
body20.CreateShape(boxDef20);
body20.SetMassFromShapes();
///////////////////
var rjdDef:b2RevoluteJointDef = new b2RevoluteJointDef();
rjdDef.Initialize(body2, body20, body20.GetWorldCenter() );
rjdDef.enableLimit=true;
// rjdDef.maxMotorTorque=16600.0;
//rjdDef.motorSpeed=500.0;
rjdDef.enableMotor=true;
rjdDef.lowerAngle=-0.18*3.14
rjdDef. upperAngle=0.25*3.14
rev1 = m_world.CreateJoint(rjdDef) as b2RevoluteJoint;
/////// center is static and other is dynamic .. and you can play with dynamic///
somthing like this
body2.SetAngularVelocity(ang);
Wednesday, April 14, 2010
cocos2d updates implementation
Thursday, April 8, 2010
Particle effect Implementation
emitter = [[CCParticleMeteor alloc] init];
emitter = [[CCParticleFire alloc] init];
emitter.texture = [[CCTextureCache sharedTextureCache] addImage:@"fire.png"];
emitter.position = ccp(location.x,location.y);
emitter.life = 0.2f;
emitter.duration = 0.3f;
emitter.lifeVar = 0.3f;
[self addChild:emitter];
Monday, March 29, 2010
Wednesday, March 10, 2010
Animate sprite
[self addChild:sheet99 z:4 tag:kTagSpriteSheet];
sprite99 = [sheet99 createSpriteWithRect:CGRectMake(0,0,300,400)];//32 * idx,32 * idy,32,32
sprite99.position=ccp(4,14);
[sheet99 addChild:sprite99 z:7];
CCAnimation *animation = [CCAnimation animationWithName:@"dance" delay:.1f ];
[animation addFrameWithTexture:sheet99.texture rect:CGRectMake(-121,0,242,400)];//-121
[animation addFrameWithTexture:sheet99.texture rect:CGRectMake(0, 0, 242,400)];//0,0
id action = [CCAnimate actionWithAnimation:animation];
// Run the animation
//id repeatAction = [CCRepeat actionWithAction:action times:100];
// To repeat forever, use this
id repeatAction = [CCRepeatForever actionWithAction:action];
[sprite99 runAction:repeatAction];
body and updation
bodyDef9c8.type =b2_staticBody;
bodyDef9c8.position.Set(9,9);//
//bodyDef9c8.angle=-58;
//bodyDef.userData = sprite;
b2Body* body9c8;
//= world->CreateBody(&groundBodyDef5);
body9c8 = world->CreateBody(&bodyDef9c8);
// Define another box shape for our dynamic body.
b2PolygonShape dynamicBox9c8;
dynamicBox9c8.SetAsBox(1.7f, .1f);//These are mid points for our 1m box
// Define the dynamic body fixture.
b2FixtureDef fixture9c8;
//fixture99.userData = @"Box";
fixture9c8.shape = &dynamicBox9c8;
fixture9c8.density = 0;
fixture9c8.friction = 0.3f;
fixture9c8.restitution=1.1f;
body9c8->CreateFixture(&fixture9c8);
#####################
update
###################
body0->SetTransform (b2Vec2(8,12),0);//target replaced by setXform