I am making a game using And Engine, when i tried to make it in generic way that works on all devices then i am in trouble...
I need to set a sprite on specific position of background sprite that should work on all screens... My background screen has same size as dimension of Device..
I tried to use pixel let say Glaxy S3 ha dimensions 720*1280
And i set according to it my sprite at location (584,608)
and my HTC experia ha dimensions (320,480)
SO i need to set it on (244,172) ....
I have tried all the following ways to set the position of sprites in generic way but not if any work...
I have tried alot of following things to make some formula that enables me to do it but unable to find any.. please advise
final Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
metrics.density;
metrics.densityDpi;
metrics.heightPixels);
metrics.scaledDensity);
metrics.widthPixels);
metrics.xdpi);
metrics.ydpi);
Point point = getDisplaySize(display);
CAMERA_WIDTH = point.x;
CAMERA_HEIGHT = point.y;
DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm);
double x = Math.pow(dm.widthPixels/dm.xdpi,2);
double y = Math.pow(dm.heightPixels/dm.ydpi,2);
double screenInches = Math.sqrt(x+y);
int widthPix = (int) Math.ceil(dm.widthPixels * (dm.densityDpi / 160.0));
//CAMERA_WIDTH = display.getWidth();
//CAMERA_HEIGHT = display.getHeight();
Problem is little bit complex.. As i told above I tried to use pixel let say Glaxy S3 ha *dimensions 720*1280 And required sprite location is (584,608) so i set in manner ( CAMERA_WIDTH/1.233f,CAMERA_HEIGHT/2.112f)*
BUT HTC experia has dimensions *320*480 So the required positions according to ( CAMERA_WIDTH/1.233f,CAMERA_HEIGHT/2.112f) is (2599.5,227.27)* but this wrong according to display... when i set it on (244,172) for experia its working perfect.... please help.