开发者

Issues with screen sizes and activity rendering

I'm currently developing my first android app, and my first game. I've been developing on a netbook with a CliqXT (HVGA). Things are going well, it renders perfectly on the smaller screen. I knew I'd have some issues when rendering on larger s开发者_如何学编程creens, but the issues I'm having are not what I was expecting and I'm kind of stuck.

So basically the game consists of a main SurfaceView which I'm rendering the tiled game world on to. I followed this tutorial to get started, and my structure is still pretty similar except that it calculates the boundries based on the player location:

http://www.droidnova.com/create-a-scrollable-map-with-cells-part-i,654.html

The game also has various buildings the player can enter. Upon entering it launches another activity for that particular building. The building activities are just normal Views with Android UI stuff defined in XML (Buttons, TextViews, etc).

What I expected to happen:

So I expected the the building UIs to render correctly on the larger screen. I specified all dimensions in "dp" and fonts in "sp" in hopes that they'd scale correctly. I expected the actual game tilemap to render generally correctly, but maybe be really tiny due to the higher resolution / dpi. I'm using a very similar function to the tutorial linked above (calculateLoopBorders(), my version is pasted below) to calculate how many tiles to render based on screen height and width (getHeight() and getWidth()).

What is actually happening:

The whole game is just being rendered as if it's HVGA. The tilemap, and the building UIs are just scaled down to the smaller screen size, leaving black borders around the left, right, and bottom (see images).

If anyone can point me in the right direction it'd be greatly appreciated, thanks a lot!

(Some of you may recognize this public domain DOS classic)

Issues with screen sizes and activity rendering

Issues with screen sizes and activity rendering

Edit: Thanks Christian for fixing code formatting.

mCellHeight and mCellWidth are the width/height of the cells in pixels

mMapHeight and mMapWidth are the width/height of the total game world in number of tiles

  public void calculateLoopBorders() {

  mWidth = getWidth();
  mHeight = getHeight();


  mStartRow = (int) Math.max(0, mPlayer.mRow - ((int) (mHeight / 2) / mCellHeight));
  mStartCol = (int) Math.max(0, mPlayer.mCol - ((int) (mWidth / 2) / mCellWidth));

  mMaxRow = (int) Math.min(mMapHeight, mStartRow + (mHeight / mCellHeight)) + 1;
  mMaxCol = (int) Math.min(mMapWidth, mStartCol + (mWidth / mCellWidth));

  if (mMaxCol >= mMapWidth) {
   mStartCol = mMaxCol - (mWidth / mCellWidth);
  }

  if (mMaxRow >= mMapHeight) {
   mStartRow = mMaxRow - (mHeight / mCellHeight); 
  }

  int x1 = mStartCol * mCellWidth;
  int y1 = mStartRow * mCellHeight;
  int x2 = x1 + mWidth;
  int y2 = y1 + mHeight;

  mBgSrcRect = new Rect(x1, y1, x2, y2);
  mBgDestRect = new Rect(0,0, mWidth, mHeight);
 }


I figured it out. I was targeting 1.5 in the Project so it was assuming HVGA. Targeting 2.1 fixes the issue and the bitmaps even seem to scale correctly using some kind of android magic.

I still have a question though, when I finish this game I want it to work with 1.5+ devices. Do I need to put separate builds into the market, one for each device class? This seems like a lot of trouble for something that could be handled in a line or 2 of code in the app itself... but I've never released an app so maybe it's easily handled in the process.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜