1

I am developing android game application which provide tracing letter functionality.This is the first time i am working with android graphics.Here I am using Canvas for my app.I want to display dotted letter on canvas which allows user to trace letters on screen.For that i created images of dotted letters and set those images in background.

Now i want to plot points on these dotted letter image at particular (x,y) coordinate. But problem is that android canvas depends on different screen size. Therefore i'll have to scale these point(x,y) coordinates according to screen size.I also referred this link but couldn't get clear idea.

Please help me to solve this problem. Thanks.

Community
  • 1
  • 1
Zankhna
  • 4,570
  • 9
  • 62
  • 103

1 Answers1

0

First find the height and width of the screen .

int width = game.getWindowManager().getDefaultDisplay().getWidth();
int height = game.getWindowManager().getDefaultDisplay().getHeight();

Scale Background to cover the screen

Bitmap background_scaled=Bitmap.createScaledBitmap(background, width, height, true);

Convert (x,y) --> (x_scaled,y_scaled)

int x_scaled=x*((float)width/(float)background.getWidth());
int y_scaled=y*((float)width/(float)background_getHeight());

Draw the point

canvas.drawPoint(x_scaled,y_scaled,new Paint());
manpreet singh
  • 1,029
  • 9
  • 15