ingsaurabh
ingsaurabh

Reputation: 15269

Android Game Programming

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?

Upvotes: 0

Views: 565

Answers (5)

Nicolas Gramlich
Nicolas Gramlich

Reputation: 2790

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

Upvotes: 1

chikka.anddev
chikka.anddev

Reputation: 9629

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.

Upvotes: 0

Matt
Matt

Reputation: 3847

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.

Upvotes: 1

Reuben Scratton
Reuben Scratton

Reputation: 38707

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.

Upvotes: 1

Lie Ryan
Lie Ryan

Reputation: 64837

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.

Upvotes: -1

Related Questions