box2d and parallax

This commit is contained in:
feroult
2017-11-23 10:35:39 -02:00
parent 82af4ef286
commit d1b547ee1a
2 changed files with 16 additions and 13 deletions

View File

@ -22,11 +22,11 @@ abstract class Box2DComponent extends Component {
Box2DComponent(this.dimensions,
{int worldPoolSize: DEFAULT_WORLD_POOL_SIZE,
int worldPoolContainerSize: DEFAULT_WORLD_POOL_CONTAINER_SIZE,
double gravity: DEFAULT_GRAVITY,
this.velocityIterations: DEFAULT_VELOCITY_ITERATIONS,
this.positionIterations: DEFAULT_POSITION_ITERATIONS,
double scale: DEFAULT_SCALE}) {
int worldPoolContainerSize: DEFAULT_WORLD_POOL_CONTAINER_SIZE,
double gravity: DEFAULT_GRAVITY,
this.velocityIterations: DEFAULT_VELOCITY_ITERATIONS,
this.positionIterations: DEFAULT_POSITION_ITERATIONS,
double scale: DEFAULT_SCALE}) {
this.world = new World.withPool(new Vector2(0.0, gravity),
new DefaultWorldPool(worldPoolSize, worldPoolContainerSize));
this.viewport = new Viewport(dimensions, scale);
@ -109,19 +109,19 @@ class Viewport extends ViewportTransform {
Viewport(this.dimensions, this.scale)
: super(new Vector2(dimensions.width / 2, dimensions.height / 2),
new Vector2(dimensions.width / 2, dimensions.height / 2), scale);
new Vector2(dimensions.width / 2, dimensions.height / 2), scale);
double alignBottom(double height) =>
double worldAlignBottom(double height) =>
-(dimensions.height / 2 / scale) + height;
/**
* Computes the number of horizontal pixels of this viewport considering a
* Computes the number of horizontal world meters of this viewport considering a
* percentage of its width.
*
* @param percent percetage of the width in [0, 1] range
*/
double width(double percent) {
return percent * (dimensions.width / 2 / scale);
double worldWidth(double percent) {
return percent * (dimensions.width / scale);
}
}
@ -147,8 +147,8 @@ abstract class BodyComponent extends Component {
void render(Canvas canvas) {
body.getFixtureList();
for (Fixture fixture = body.getFixtureList();
fixture != null;
fixture = fixture.getNext()) {
fixture != null;
fixture = fixture.getNext()) {
switch (fixture.getType()) {
case ShapeType.CHAIN:
throw new Exception("not implemented");
@ -202,7 +202,8 @@ abstract class BodyComponent extends Component {
}
void drawPolygon(Canvas canvas, List<Offset> points) {
final path = new Path()..addPolygon(points, true);
final path = new Path()
..addPolygon(points, true);
final Paint paint = new Paint()
..color = new Color.fromARGB(255, 255, 255, 255);
// ..style = PaintingStyle.stroke;

View File

@ -100,8 +100,10 @@ class ParallaxComponent extends PositionComponent {
return;
}
canvas.save();
prepareCanvas(canvas);
_drawLayers(canvas);
canvas.restore();
}
void _drawLayers(Canvas canvas) {