render method

void render(
  1. Canvas canvas,
  2. Size size
)

Implementation

void render(Canvas canvas, Size size){
  if(tileSets.isEmpty || allTileImage == null) return;
  camera.zoomCamera(tileSets[selectedTileSet].zoom(camera.viewportWidth));
  Rect totalRect = Rect.fromLTWH(0, 0, camera.viewportWidth, camera.viewportHeight);
  Vector3 newPosition = Vector3.copy(tileSets[selectedTileSet].position)..scale(camera.zoom);
  newPosition.applyMatrix4(camera.lookAtMatrix);

  double scale = (camera.viewportWidth)/(tileSets[selectedTileSet].size.width);

  canvas.drawAtlas(
    allTileImage!,
    [RSTransform.fromComponents(
      rotation: 0,
      scale: scale,
      anchorX: 0,
      anchorY: 0,
      translateX: newPosition.x,
      translateY: newPosition.y
    )],
    [Rect.fromLTWH(
      0,
      tileSets[selectedTileSet].offsetHeight.toDouble(),
      tileSets[selectedTileSet].size.width,
      tileSets[selectedTileSet].size.height
    )],
    [],
    BlendMode.srcOver,
    null,
    Paint()
  );
  if(tileSets[selectedTileSet].grid.rects.isNotEmpty){
    _drawGrid(canvas,totalRect);
  }
  if(!isClicked){
    tapLocation = null;
  }
}