0

I'm trying to make a game for Android, I have a problem when dealing with multiple resolutions, this is a example of my gameview: http://oi42.tinypic.com/vh6ir6.jpg.

In the small area, there are several pieces of information, while the largest area is my play area. My purpose is to prevent the image (bitmap) from going beyond the edges of the playing area. This is partially working, but it only works with 800x432 resolution (the resolution of my tablet xD )

This is my code:

case MotionEvent.ACTION_MOVE:

    //left edge

                        if (deltaX <= 90 && deltaY <= 400 && deltaY >28){
                        Static_PositionX = 52;
                            Static_PositionY = (int)deltaY-35;
                            Drag = false;
                        }
//down edge
                        else if (deltaY >= 380 && deltaX > 90 && deltaX <770) { 
                          Static_PositionX =  (int)deltaX-42;
                          Static_PositionY = 360;
                          Drag = false;
//right edge
                         }else  if((deltaY <= 390 && deltaY > 20) && deltaX > 770){
                             Static_PositionX =723;
                            Static_PositionY = (int)deltaY-35;
                          Drag = false;

                         }
// up edge
                         else if ((deltaX >= 90 && deltaX < 770) && deltaY <= 35 ){
                            Static_PositionX =(int)deltaX-42;
                                Static_PositionY = 0;
                             Drag = false;

                    }

where deltaX and deltaY are my image coordinates and Static_PositionX/Static_PositionY are a random start position

deltaX=event.getX();
deltaY=event.getY();
4

2 回答 2

1

停止对屏幕尺寸使用绝对数字。

有关如何为当前设备获取它们的信息,请参阅 SO中的此答案。

于 2013-06-27T20:20:32.503 回答
0

为特定分辨率设计游戏。

boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
int frameBufferWidth = isLandscape ? 480 : 320;
int frameBufferHeight = isLandscape ? 320 : 480;
Bitmap frameBuffer = Bitmap.createBitmap(frameBufferWidth,
            frameBufferHeight, Config.RGB_565);

Canvas canvas = new Canvas(frameBuffer); // Do all your drawing on frame buffer

当您实际在屏幕上渲染图形时,在实际画布上绘制帧缓冲区。这样,将为您处理不同屏幕的所有缩放。

Canvas canvas = holder.lockCanvas();
canvas.getClipBounds(dstRect);
canvas.drawBitmap(framebuffer, null, dstRect, null);                           
holder.unlockCanvasAndPost(canvas);
于 2013-06-27T20:38:32.320 回答