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
Wednesday, July 8, 2009
Monday, July 6, 2009
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;
}
}
}
}
}
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;
}
}
}
}
}
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
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;
maze.CreateShape(boxDefk);
bodies.push(maze);
}
}
}
maze.SetMassFromShapes();*/
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;
maze.CreateShape(boxDefk);
bodies.push(maze);
}
}
}
maze.SetMassFromShapes();*/
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;
boxDef.SetAsBox(.5,.8);
bodyDef.position.Set(10,1);
bodyDef.angle = 45//Math.random() * Math.PI;
body = m_world.CreateBody(bodyDef);
shape1=body.CreateShape(boxDef);//collsion wer shape1:*
body.SetMassFromShapes();
/////////////////////////////////////////////////////////////////
Skin------>
wheel.x=body.GetPosition().x* 30;
wheel.y=body.GetPosition().y* 30
;
wheel.rotation = body.GetAngle() * (180/Math.PI);
m_sprite.addChild(wheel);
///////////////////////////////////////////////////////////////////////
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;
boxDef.SetAsBox(.5,.8);
bodyDef.position.Set(10,1);
bodyDef.angle = 45//Math.random() * Math.PI;
body = m_world.CreateBody(bodyDef);
shape1=body.CreateShape(boxDef);//collsion wer shape1:*
body.SetMassFromShapes();
/////////////////////////////////////////////////////////////////
Skin------>
wheel.x=body.GetPosition().x* 30;
wheel.y=body.GetPosition().y* 30
;
wheel.rotation = body.GetAngle() * (180/Math.PI);
m_sprite.addChild(wheel);
///////////////////////////////////////////////////////////////////////
Monday, May 11, 2009
make a object stop after sometime
if (bullet.GetLinearVelocity().Length() < 0.001){
stoppedForFrames += 1;
}
else{
stoppedForFrames = 0;
}
if (stoppedForFrames >= 15){
trace("stopped");
}
stoppedForFrames += 1;
}
else{
stoppedForFrames = 0;
}
if (stoppedForFrames >= 15){
trace("stopped");
}
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 {
unLock=my_so.data.UNLOCK
;
}
//////////////////////////////////
make movieclips (to show all levels)
//////
L1.buttonMode = true;//// its open
L1.addEventListener(MouseEvent.CLICK,LevelPlay);
function LevelPlay(e:Event) {
gotoAndStop("play");
distance_joint1();
Level=1
;
}
//////////////////
L2.addEventListener(MouseEvent.CLICK,LevelPlay1);///its closed
function LevelPlay1(e:Event) {
if(L2.buttonMode==true)
{
gotoAndStop("play");
distance_joint1();
Level=2
}
;
}
//////////
/// this is the code for making button visible and non visible
for( var i=1;i<=unLock;i++)
{
this["L"+i].buttonMode=true//mouseEnabled=true//alpha=0//buttonMode=true
//trace(this["L"+i])
}
//////////////////////////////////////
finaly in UPdate fucntion() pass the data and store it like this
//////////////////
my_so.data.UNLOCK=Level
my_so.flush()
my_so.close()
////////////////////////////////////////
its done :)
/////////////////////////
var unLock:*;
var my_so:SharedObject = SharedObject.getLocal("store4");
if (my_so.size == 0) {
unLock = Level
;
} else {
unLock=my_so.data.UNLOCK
;
}
//////////////////////////////////
make movieclips (to show all levels)
//////
L1.buttonMode = true;//// its open
L1.addEventListener(MouseEvent.CLICK,LevelPlay);
function LevelPlay(e:Event) {
gotoAndStop("play");
distance_joint1();
Level=1
;
}
//////////////////
L2.addEventListener(MouseEvent.CLICK,LevelPlay1);///its closed
function LevelPlay1(e:Event) {
if(L2.buttonMode==true)
{
gotoAndStop("play");
distance_joint1();
Level=2
}
;
}
//////////
/// this is the code for making button visible and non visible
for( var i=1;i<=unLock;i++)
{
this["L"+i].buttonMode=true//mouseEnabled=true//alpha=0//buttonMode=true
//trace(this["L"+i])
}
//////////////////////////////////////
finaly in UPdate fucntion() pass the data and store it like this
//////////////////
my_so.data.UNLOCK=Level
my_so.flush()
my_so.close()
////////////////////////////////////////
its done :)
Monday, May 4, 2009
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);
trace(forcex)
if (Math.abs(forcex)>=1&&Math.abs(forcey)>=1) {
body.ApplyForce( new b2Vec2(10/forcex, 50/forcey), body.GetWorldCenter());
}
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);
trace(forcex)
if (Math.abs(forcex)>=1&&Math.abs(forcey)>=1) {
body.ApplyForce( new b2Vec2(10/forcex, 50/forcey), body.GetWorldCenter());
}
Subscribe to:
Posts (Atom)