render method
Implementation
void render(Canvas canvas, Size size){
if(sprites.isEmpty) return;
Vector3 newCameraPosition = Vector3.copy(camera.position);
newCameraPosition.applyMatrix4(camera.lookAtMatrix);
Rect totalRect = Rect.fromLTWH(0, 0, camera.viewportWidth, camera.viewportHeight);
canvas.saveLayer(totalRect, Paint());
for(int i = 0; i < sprites.length;i++){
Vector3 newPosition = Vector3.copy(sprites[i].position)..scale(camera.zoom);
newPosition.applyMatrix4(camera.lookAtMatrix);//..applyMatrix4(Matrix4.identity()..translate((camera.zoom*offsetVal.width)-offsetVal.width,(camera.zoom*offsetVal.height)-offsetVal.height));
paintImage(
canvas: canvas,
rect: Rect.fromLTWH(newPosition.x, newPosition.y, sprites[i].sprite.width*camera.zoom,sprites[i].sprite.height*camera.zoom),
image: sprites[i].sprite,
fit: BoxFit.fill
);
CanvasRects rect = createRect(Size(sprites[i].sprite.width*1.0,sprites[i].sprite.height*1.0), sprites[i].position, sprites[i].color, i, i,type: SelectedType.image);
final paint = Paint()
..style = PaintingStyle.stroke
..strokeWidth = 2
..color = rect.color
..blendMode = BlendMode.srcOver;
canvas.drawRect(rect.rect, paint);
}
if(collisions.isNotEmpty){
for(int i = 0; i < collisions.length;i++){
Vector3 newPosition = Vector3.copy(collisions[i].position)..scale(camera.zoom);
newPosition.applyMatrix4(camera.lookAtMatrix);//..applyMatrix4(Matrix4.identity()..translate((camera.zoom*offsetVal.width)-offsetVal.width,(camera.zoom*offsetVal.height)-offsetVal.height));
CanvasRects rect = createRect(collisions[i].size, collisions[i].position, Colors.green.withAlpha(180), i, i, type: SelectedType.rect);
bool accent = false;
if(objectTappedOn.isNotEmpty){
for(int k = 0; k < objectTappedOn.length;k++){
if(objectTappedOn[k].animation == i){
accent = true;
break;
}
}
}
final paint = Paint()
..style = PaintingStyle.fill
..color = accent?const Color(0xff0055ff):rect.color
..blendMode = BlendMode.srcOver;
canvas.drawRect(rect.rect, paint);
}
}
canvas.restore();
Vector3 newPosition = Vector3.zero()..scale(camera.zoom);
newPosition.applyMatrix4(camera.lookAtMatrix);
canvas.drawPoints(PointMode.points, [Offset(newPosition.x,newPosition.y)], Paint()..color=Colors.green..strokeWidth=5);
}