Class Canvas


  • public class Canvas
    extends java.lang.Object
    Used to control the size of the canvas displaying the application's graphics, independent from the size of the screen. This allows the application to control the zoom level, therefore controlling the user experience in situations where the same application is used across a variety of devices with different screen sizes. This class allows to translate between the two coordinate systems.

    Although the canvas is given a preferred size and aspect ratio upon creation, it is not guaranteed that these will ever be used. This is especially true for mobile apps, where the application will usually fill the entire screen.

    • Constructor Summary

      Constructors 
      Constructor Description
      Canvas​(int preferredWidth, int preferredHeight)  
      Canvas​(int preferredWidth, int preferredHeight, float zoomLevel)  
    • Constructor Detail

      • Canvas

        public Canvas​(int preferredWidth,
                      int preferredHeight,
                      float zoomLevel)
      • Canvas

        public Canvas​(int preferredWidth,
                      int preferredHeight)
    • Method Detail

      • resize

        public void resize​(int screenWidth,
                           int screenHeight)
        Sets the screen dimensions to the specified values. This method should be called by the renderer when the application window is first created, and whenever the window is resized.
      • offset

        public void offset​(int offsetX,
                           int offsetY)
      • getWidth

        public int getWidth()
      • getHeight

        public int getHeight()
      • getScreenWidth

        public int getScreenWidth()
      • getScreenHeight

        public int getScreenHeight()
      • getZoomLevel

        public float getZoomLevel()
      • toCanvasX

        public int toCanvasX​(int screenX)
      • toCanvasY

        public int toCanvasY​(int screenY)
      • toScreenX

        public int toScreenX​(float canvasX)
      • toScreenY

        public int toScreenY​(float canvasY)