Hello to all
I'm new in the Box2D world, and that's exactly my problem 🙂
I have created my first game, but I have some performance issues that I couldn't fix on my own ... so I have to ask for some help.
The game link is this: http://gamesloop.com/2009/11/18/catch/
So ... as you can see .... the game hangs a little, for a few mSeconds (milliSeconds) when a new object is added to the world. A new ball is added randomly with this function:
There are other functions involved in this block of code, but those bits of code are not important, and the function name will tell you what the function's role is.
I have tryed both versions of calling the createObject function. Based on Timer event and also with ENTER_FRAME event, but both of these present the same issue, and exactly the same !!!
My code is trimmed down to only creating the balls, I mean no images no other functions no nothing. I've been fighting with this for 3-4 days. Is this a Box2D issue or what ?
P.S. 1 beer to whoever helps me with this issue :p
P.S2 NOT JOKING 🙂
I'm new in the Box2D world, and that's exactly my problem 🙂
I have created my first game, but I have some performance issues that I couldn't fix on my own ... so I have to ask for some help.
The game link is this: http://gamesloop.com/2009/11/18/catch/
So ... as you can see .... the game hangs a little, for a few mSeconds (milliSeconds) when a new object is added to the world. A new ball is added randomly with this function:
Code:
public function createObject(rX:Number,rY:Number,mX:Number,mY:Number,type:String,randomNumber:Number) {
// Add some objects
bodyDef = new b2BodyDef();
bodyDef.position.x=mX/30;
bodyDef.position.y=mY/30;
// CIRCLE
if (type=="CIRCLE") {
circleDef = new b2CircleDef();
circleDef.radius=rX;
circleDef.density=1.0;
circleDef.friction=0.5;
circleDef.restitution=0.5;
bodyDef.userData = new PhysCircle();
bodyDef.isBullet=true;
// here is set the type of the ball with the randomType function
var t:Number=randomType();
bodyDef.userData.gotoAndStop(t);
bodyDef.userData.name="Circle";
bodyDef.userData.myNumber=nrEggs;
bodyDef.userData.myValue=ballValue();
addChild(bodyDef.userData);
body=m_world.CreateBody(bodyDef);
body.CreateShape(circleDef);
}
body.SetMassFromShapes();
addChild(bodyDef.userData);
Update(null); // This is so the ball will not apper for a short time on the upper-left corner of the stage
}
// Add some objects
bodyDef = new b2BodyDef();
bodyDef.position.x=mX/30;
bodyDef.position.y=mY/30;
// CIRCLE
if (type=="CIRCLE") {
circleDef = new b2CircleDef();
circleDef.radius=rX;
circleDef.density=1.0;
circleDef.friction=0.5;
circleDef.restitution=0.5;
bodyDef.userData = new PhysCircle();
bodyDef.isBullet=true;
// here is set the type of the ball with the randomType function
var t:Number=randomType();
bodyDef.userData.gotoAndStop(t);
bodyDef.userData.name="Circle";
bodyDef.userData.myNumber=nrEggs;
bodyDef.userData.myValue=ballValue();
addChild(bodyDef.userData);
body=m_world.CreateBody(bodyDef);
body.CreateShape(circleDef);
}
body.SetMassFromShapes();
addChild(bodyDef.userData);
Update(null); // This is so the ball will not apper for a short time on the upper-left corner of the stage
}
There are other functions involved in this block of code, but those bits of code are not important, and the function name will tell you what the function's role is.
I have tryed both versions of calling the createObject function. Based on Timer event and also with ENTER_FRAME event, but both of these present the same issue, and exactly the same !!!
My code is trimmed down to only creating the balls, I mean no images no other functions no nothing. I've been fighting with this for 3-4 days. Is this a Box2D issue or what ?
P.S. 1 beer to whoever helps me with this issue :p
P.S2 NOT JOKING 🙂