0

I have simple 2D puzzle game earlier I created it extending view and everything goes fine unless I tested it on smaller device. My half of the game doesnt appear on device someone told me to use surface view I tried that also but of no use can anybody tell me whats the problem I placed various graphics object like this

bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ring);
canvas.drawBitmap(bitmap, 45, 250, paint);
canvas.drawBitmap(bitmap, 135, 250, paint);
canvas.drawBitmap(bitmap, 225, 250, paint);

i.e. I used static values is this not the correct way or what I am doing wrong?

asked Jan 13, 2011 at 13:20

5 Answers 5

1

Get the screen's height and width:

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int screenHeight = dm.heightPixels;
int screenWidth = dm.widthPixels;

Then scale everything using those values... You'll probably need to specify all vertices of the bitmaps, so that it scales properly.

answered Jan 13, 2011 at 16:55
Sign up to request clarification or add additional context in comments.

1 Comment

you mean to say convert it in perecentage as we do in css
1

If you are assuming a screen size of 320x480 then you should be setting <supports-screens android:anyDensity="false"> in your manifest. It defaults to true... setting it to false means Android will take care of scaling your graphical output to the actual screen.

Of course this automatic downscaling can look less than perfect... ideally you should not be assuming a screen size.

answered Jan 13, 2011 at 13:28

3 Comments

I want to support all screen sizes any thing else if this is wrong way what is the best practise to do this
Try autoscaling first, maybe it'll look alright. It depends entirely on what your game looks like. If it looks bad, then you'll need to change your game code. But you might get away with it.
Thanks for your answer although I got what I wanted by scaling coordinates using device height and width but I am not happy with it there must be some thing that will automatically do this as my colleague has done this already in surfaceview using hard coded values but he dont know exactly how that happens
1

You could use a game engine like AndEngine or Badlogic Games so you don't have to care about stuff like this at all.

Alexander
23.5k11 gold badges65 silver badges74 bronze badges
answered Jan 27, 2011 at 9:28

1 Comment

When advertising your own engine it's customary to mention the fact ;) However its clear the guy wants to do it himself.
0

I think you may have to get the height and width of the window at the start and according to the mobile's dimensions, you have to set that.

Mxyk
10.7k16 gold badges60 silver badges76 bronze badges
answered Jan 13, 2011 at 13:28

Comments

-1

Of course it won't work. If you need your game to be playable in multiple screen sizes, you cannot assume that the screen is of particular size.

answered Jan 13, 2011 at 13:27

3 Comments

so how would I do it any example
Yes he can : he can assume it is and then scale. Which is the point of the Q. ie assume its 640x480 for a crude example then query the real dimensions and scale.
@RichieHH: Not all screens are of the same aspect ratio. If you simply rescale the game, you'll either stretch the game out of proportion or get black borders around the game. Additionally, with high density Retina displays becoming common, some of your users will get buttons that are too small while others get the same button obscenely too big. Neither is a good thing. You need to design the screen with fluid or responsive design techniques to handle multiple screen sizes. Android framework provides extensive support for this.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.