Hi everyone,
I'm farely new to box2D since this is the first project I've worked with it but the project itself is nearly completed, just needs some optimization.
At the moment I'm not very happy with the performance and I'm not sure if its my code, flash itself, the game's complexity or box2D not being used in the correct manner so here's a couple questions I'd love to see answers for if anyone is kind enough.
First off the fla's framerate is set to 60fps for the animations to run smoothly but the game's engine is running on a FRIM 30fps loop and box2d is being used via quickbox2d at a step of 1/30 with 10 iterations.
Apart from the Player entity there are several non-box2d entities with choreographic AI (no more then 5 on state simultaniously, usually 2/3), there's also some other game logic conditions being checked in the game's loop but I don't believe it's the cause of chocking in the performance.
The Player entity which is a 'lunar-lander-like' ship (jets apply impulses up and sideways) and here is the biggest 'doubt' I have about the whole thing, for the movement I'm using ApplyForce as such:
Any ideas on how to optimize things would be apreciated, thanks in advance.
I'm farely new to box2D since this is the first project I've worked with it but the project itself is nearly completed, just needs some optimization.
At the moment I'm not very happy with the performance and I'm not sure if its my code, flash itself, the game's complexity or box2D not being used in the correct manner so here's a couple questions I'd love to see answers for if anyone is kind enough.
First off the fla's framerate is set to 60fps for the animations to run smoothly but the game's engine is running on a FRIM 30fps loop and box2d is being used via quickbox2d at a step of 1/30 with 10 iterations.
Apart from the Player entity there are several non-box2d entities with choreographic AI (no more then 5 on state simultaniously, usually 2/3), there's also some other game logic conditions being checked in the game's loop but I don't believe it's the cause of chocking in the performance.
The Player entity which is a 'lunar-lander-like' ship (jets apply impulses up and sideways) and here is the biggest 'doubt' I have about the whole thing, for the movement I'm using ApplyForce as such:
Code:
if (_keyboard.isDown(_keys.UP)) {
_player.body.ApplyForce(new b2Vec2(_engine._elapsed * _playerProps.jetUp[0], _engine._elapsed * _playerProps.jetUp[1]), _player.body.GetWorldCenter());
}
if (_keyboard.isDown(_keys.DOWN)) {
_player.body.ApplyForce(new b2Vec2(_engine._elapsed * _playerProps.jetDown[0], _engine._elapsed * _playerProps.jetDown[1]), _player.body.GetWorldCenter());
}
if (_keyboard.isDown(_keys.LEFT)) {
_player.body.ApplyForce(new b2Vec2(_engine._elapsed * _playerProps.jetLeft[0], _engine._elapsed * _playerProps.jetLeft[1]), _player.body.GetWorldCenter());
}
if (_keyboard.isDown(_keys.RIGHT)) {
_player.body.ApplyForce(new b2Vec2(_engine._elapsed * _playerProps.jetRight[0], _engine._elapsed * _playerProps.jetRight[1]), _player.body.GetWorldCenter());
}
_player.body.ApplyForce(new b2Vec2(_engine._elapsed * _playerProps.jetUp[0], _engine._elapsed * _playerProps.jetUp[1]), _player.body.GetWorldCenter());
}
if (_keyboard.isDown(_keys.DOWN)) {
_player.body.ApplyForce(new b2Vec2(_engine._elapsed * _playerProps.jetDown[0], _engine._elapsed * _playerProps.jetDown[1]), _player.body.GetWorldCenter());
}
if (_keyboard.isDown(_keys.LEFT)) {
_player.body.ApplyForce(new b2Vec2(_engine._elapsed * _playerProps.jetLeft[0], _engine._elapsed * _playerProps.jetLeft[1]), _player.body.GetWorldCenter());
}
if (_keyboard.isDown(_keys.RIGHT)) {
_player.body.ApplyForce(new b2Vec2(_engine._elapsed * _playerProps.jetRight[0], _engine._elapsed * _playerProps.jetRight[1]), _player.body.GetWorldCenter());
}
Any ideas on how to optimize things would be apreciated, thanks in advance.