Skip to content

Instantly share code, notes, and snippets.

@juskek
Last active August 19, 2021 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juskek/5de5b9bbd7d5fb1d283472cb878f16ce to your computer and use it in GitHub Desktop.
Save juskek/5de5b9bbd7d5fb1d283472cb878f16ce to your computer and use it in GitHub Desktop.
void render(Canvas canvas) {
/// BACKGROUND (BOTTOMMOST LAYER)
Rect bgRect = Rect.fromLTWH(0, 0, screenSize!.width,screenSize!.height);
Paint bgPaint = Paint();
bgPaint.color = Color(0xffbbcc00);
canvas.drawRect(bgRect, bgPaint);
/// TARGET BOX (TOPMOST LAYER)
print(screenSize); // ! target box does not change with screen size
double screenCenterX = screenSize!.width / 2;
double screenCenterY = screenSize!.height / 2;
Rect boxRect = Rect.fromLTWH(screenCenterX - 75, screenCenterY - 75, 150, 150);
Paint boxPaint = Paint();
// CHANGE TARGET BOX COLOUR CONDITIONALLY
if (hasPressed) {
boxPaint.color = Color(0xff00ff00);
} else {
boxPaint.color = Color(0xffffffff);
}
canvas.drawRect(boxRect, boxPaint);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment