Canvas.scale - weekend data are zero, what's the problem?



  • I use canvas.scale to optimise the playing field in my game, but faced a problem - canvas.scale(x,y) x and y = 0, so there's nothing on the screen, although the logic should be the point. How can this problem be addressed?

    This is code:`public class Game extends Activity {

    public static int heightDisplay;
    public static int widthDisplay;
    

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(new GamePanel(this));

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    
    DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    
    heightDisplay = displaymetrics.heightPixels;
    widthDisplay = displaymetrics.widthPixels;
    

    }

    public static final int WIDTH = 720;
    public static final int HEIGHT = 1280;

    @Override
    public void draw(Canvas canvas)
    {

    if(canvas!=null) {
        final int savedState = canvas.save();
        canvas.scale(Game.widthDisplay/WIDTH, Game.heightDisplay/HEIGHT);
        bg.draw(canvas);
        canvas.restoreToCount(savedState);
    }
    

    }



  • The point is infinitely small, and it's not.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2