mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-04 13:08:09 +08:00 
			
		
		
		
	box2d and parallax
This commit is contained in:
		@ -22,11 +22,11 @@ abstract class Box2DComponent extends Component {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  Box2DComponent(this.dimensions,
 | 
					  Box2DComponent(this.dimensions,
 | 
				
			||||||
      {int worldPoolSize: DEFAULT_WORLD_POOL_SIZE,
 | 
					      {int worldPoolSize: DEFAULT_WORLD_POOL_SIZE,
 | 
				
			||||||
      int worldPoolContainerSize: DEFAULT_WORLD_POOL_CONTAINER_SIZE,
 | 
					        int worldPoolContainerSize: DEFAULT_WORLD_POOL_CONTAINER_SIZE,
 | 
				
			||||||
      double gravity: DEFAULT_GRAVITY,
 | 
					        double gravity: DEFAULT_GRAVITY,
 | 
				
			||||||
      this.velocityIterations: DEFAULT_VELOCITY_ITERATIONS,
 | 
					        this.velocityIterations: DEFAULT_VELOCITY_ITERATIONS,
 | 
				
			||||||
      this.positionIterations: DEFAULT_POSITION_ITERATIONS,
 | 
					        this.positionIterations: DEFAULT_POSITION_ITERATIONS,
 | 
				
			||||||
      double scale: DEFAULT_SCALE}) {
 | 
					        double scale: DEFAULT_SCALE}) {
 | 
				
			||||||
    this.world = new World.withPool(new Vector2(0.0, gravity),
 | 
					    this.world = new World.withPool(new Vector2(0.0, gravity),
 | 
				
			||||||
        new DefaultWorldPool(worldPoolSize, worldPoolContainerSize));
 | 
					        new DefaultWorldPool(worldPoolSize, worldPoolContainerSize));
 | 
				
			||||||
    this.viewport = new Viewport(dimensions, scale);
 | 
					    this.viewport = new Viewport(dimensions, scale);
 | 
				
			||||||
@ -109,19 +109,19 @@ class Viewport extends ViewportTransform {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  Viewport(this.dimensions, this.scale)
 | 
					  Viewport(this.dimensions, this.scale)
 | 
				
			||||||
      : super(new Vector2(dimensions.width / 2, dimensions.height / 2),
 | 
					      : 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;
 | 
					      -(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.
 | 
					   * percentage of its width.
 | 
				
			||||||
   *
 | 
					   *
 | 
				
			||||||
   * @param percent percetage of the width in [0, 1] range
 | 
					   * @param percent percetage of the width in [0, 1] range
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  double width(double percent) {
 | 
					  double worldWidth(double percent) {
 | 
				
			||||||
    return percent * (dimensions.width / 2 / scale);
 | 
					    return percent * (dimensions.width / scale);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -147,8 +147,8 @@ abstract class BodyComponent extends Component {
 | 
				
			|||||||
  void render(Canvas canvas) {
 | 
					  void render(Canvas canvas) {
 | 
				
			||||||
    body.getFixtureList();
 | 
					    body.getFixtureList();
 | 
				
			||||||
    for (Fixture fixture = body.getFixtureList();
 | 
					    for (Fixture fixture = body.getFixtureList();
 | 
				
			||||||
        fixture != null;
 | 
					    fixture != null;
 | 
				
			||||||
        fixture = fixture.getNext()) {
 | 
					    fixture = fixture.getNext()) {
 | 
				
			||||||
      switch (fixture.getType()) {
 | 
					      switch (fixture.getType()) {
 | 
				
			||||||
        case ShapeType.CHAIN:
 | 
					        case ShapeType.CHAIN:
 | 
				
			||||||
          throw new Exception("not implemented");
 | 
					          throw new Exception("not implemented");
 | 
				
			||||||
@ -202,7 +202,8 @@ abstract class BodyComponent extends Component {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void drawPolygon(Canvas canvas, List<Offset> points) {
 | 
					  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()
 | 
					    final Paint paint = new Paint()
 | 
				
			||||||
      ..color = new Color.fromARGB(255, 255, 255, 255);
 | 
					      ..color = new Color.fromARGB(255, 255, 255, 255);
 | 
				
			||||||
//      ..style = PaintingStyle.stroke;
 | 
					//      ..style = PaintingStyle.stroke;
 | 
				
			||||||
 | 
				
			|||||||
@ -100,8 +100,10 @@ class ParallaxComponent extends PositionComponent {
 | 
				
			|||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    canvas.save();
 | 
				
			||||||
    prepareCanvas(canvas);
 | 
					    prepareCanvas(canvas);
 | 
				
			||||||
    _drawLayers(canvas);
 | 
					    _drawLayers(canvas);
 | 
				
			||||||
 | 
					    canvas.restore();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void _drawLayers(Canvas canvas) {
 | 
					  void _drawLayers(Canvas canvas) {
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user