Friday, August 28, 2009

iphone video

skin example part 2

@ set widht, height and skin in diff class
code:
//////////////////////////////////
- (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];

i PHONE

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;
@end





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

Sleep

body.PutToSleep()

Thursday, July 23, 2009

Generic Body

AddSpringBox(12,8,2,.1,-.45)

////////////////////////
public function AddSpringBox(_x:Number,_y:Number,_halfwidth:Number,_halfheight:Number,ang:Number):void {
var bodyDef:b2BodyDef = new b2BodyDef();
bodyDef.position.Set(_x,_y);
var boxDef:b2PolygonDef = new b2PolygonDef();
boxDef.SetAsBox(_halfwidth,_halfheight);
bodyDef.angle=ang
boxDef.density = 0.0;
boxDef.restitution=1
var body:b2Body = m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();





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

m_dbgSprite.addChild(red);
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;
wallBd2l.position.Set(12,5);//8.8
//wallSd2k.restitution=1

wallSd2l.SetAsBox(.1, 2);
//wallBd2l.angle=-.45
wallB2l = m_world.CreateBody(wallBd2l);
wallB2l.CreateShape(wallSd2l);
wallB2l.SetMassFromShapes();


////////

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

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)

{
trace("rt")
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


Update()
{
var massData = new b2MassData();
massData.mass = 1;

massData.center = new b2Vec2(-1,1);
massData.I=2
wallBd.SetMass(massData);//wallBd is a body
wallBd.WakeUp()
}

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

Thursday, July 2, 2009

Searching elements in ARRAY

package{
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);
break;
}
}
}
}
}

FEEDJIT Live