Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3396232
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:22:59+00:00 2026-05-18T04:22:59+00:00

for the sake of simplicity let’s assume that I’m making a simple Pong clone

  • 0

for the sake of simplicity let’s assume that I’m making a simple Pong clone game for Android. Let’s assume that it would only be playable in the landscape mode. (ignore square phones for now).

I’d like the game to look in the same scale on each phone, to the extent that if you took a screenshot of the game on QVGA phone, and resized the screenshot to WVGA size, it would look almost the same as would the game look on WVGA phone. In other words, the paddle’s width should always be 1/32 of the screen width, the ball’s diameter should always be 1/16 of the screen width.

What would be the proper way to paint the application? It would run in standard SurfaceView that would be drawn onto a Canvas.

Let’s say that I have a high-resolution PNGs for the paddle, ball and for the game font (scoreboard, main menu).

Do I find out the physical resolution, then scale the Canvas via scale(float sx, float sy) to make all my Canvases (on QVGA and WVGA) have the same virtual resolution, and then draw exactly the same primitives on each position on each screen size?

Or can I use density-independent pixels (dip) somehow in the Canvas?

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:23:00+00:00Added an answer on May 18, 2026 at 4:23 am

    I only played once with the draw canvas functions and then switched all to opengl but the logic stays the same (I think).

    first issue you’ll want to keep a ratio constant form one phone to the other.
    in my app I add a ” black band” effect on each side.
    in onSurfaceChanged, you’ll want to calculate a ratio, this ratio will allow you to determine how much space you have to remove on each side to keep a consistent aspect to your drawing. this will give you a delta X or Y to apply to all your draws
    the following code is something I adapted from the ogl version so it might need to be tweeked a bit

    @Override
       public void onSurfaceChanged(int w, int h){
       float ratioPhysicScreen = nativeScreenResoltionW/nativeScreenResoltionH;
       float ratioWanted = GameView.getWidth()/GameView.getHeight();
       if(ratioWanted>ratioPhysicScreen){
          newHeight = (int) (w*GameView.getHeight()/GameView.getWidth());
          newWidth = w;
          deltaY = (int) ((h-newHeight)/2);
         deltaX = 0;
       }else{
          newWidth = (int) (h/GameView.getHeight()*GameView.getWidth());
          newHeight = h;
          deltaX = (int) ((w-newWidth)/2);
          deltaY = 0;       
    }
    

    then you’ll also want to be able to draw your pictures on the canvas by knowing there size as well on the canvas than there real size and that where the difference in between image.getWidth() (actual size of the picture) and a image.getScaledWidth(canvas) which give you the size of the element in dp which means how big it will appear on the screen) is important. look at the example underneath.

    public class MainMenuView extends PixelRainView{
    private Bitmap bmpPlay = null;
    private float playLeft = 0;
    private float playRight = 0;
    private float playBottom = 0;
    private float playTop = 0;
    
    public MainMenuView(Context context, AttributeSet attrs) {
        super(context,attrs);
    }
    
    
    
    @Override
    public void unLoadBitmaps() {
        super.unLoadBitmaps();
        if(bmpPlay != null){
            bmpPlay.recycle();
            bmpPlay = null;
        }
    }
    
    
    
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if(bmpPlay == null){
            bmpPlay = getBitmapFromRessourceID(R.drawable.play_bt);
            playLeft = (this.getWidth()-bmpPlay.getScaledWidth(canvas))/2; 
            playRight = playLeft + bmpPlay.getScaledWidth(canvas);
            playTop = (this.getHeight()-bmpPlay.getScaledHeight(canvas))/2;
            playBottom = playTop+bmpPlay.getScaledHeight(canvas);
        }
        canvas.drawBitmap(bmpPlay,playLeft, playTop, null);
    
        }       
    }
    
    
    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
    }
    
    
    
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_DOWN){
            float x = event.getX();
            float y = event.getY();
            //test central button
            if(x>playLeft && x<playRight && y<playBottom && y>playTop){
                Log.e("jason", "touched play");
                PixelRainView.changeView(R.layout.composedlayoutgroup);
            }
        return super.onTouchEvent(event);
    }
    }
    

    This should solve all your ratio problem cross plateforms
    I would suggest opengl because it will simplify your need for keeping a constant aspect but I guess its not an option ^^

    Hope this helps you enough

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dilemma. Let's assume(for simplicity's sake) I have four tables, with different
For the sake of simplicity, let's say that we have input strings with this
For sake of simplicity, let's assume I want to write an extension method for
For the sake of simplicity, let's assume the following tables exist: Table 1 -
For the sake of simplicity, let's just assume the integer I am passing to
I am creating a custom WPF control that let's say for simplicity sake has
For the sake of simplicity, let's assume I'm cloning twitter (I'm not). So every
Let's say I have a utility function that, for simplicity's sake (the real thing
I'm working with three tables, and for simplicity's sake let's call them table A,
I have an NSMutableArray that is populated with objects of strings. For simplicity sake

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.